M
Macario Ortega
Hi I've made a gem for supporting keyword arguments in Ruby 1.8.6 and
1.9.1. I think is a good alternative to traditional options hash, usage
is as follows:
require 'arguments'
class Example
def meth(a = :a, b = :b, c = :c)
[a,b,c]
end
class << self
def class_method(a = :a, b = :b, c = :c)
[a,b,c]
end
def other_class_method(a = :a, b = :b, c = :c)
[a,b,c]
end
named_args_for :class_method
end
named_args_for :meth, :'self.other_class_method'
end
nu = Example.new
nu.meth #=> [:a,:b,:c]
nu.meth(1, :c => Class) #=> [1,:b,Class]
nu.meth
b => nil, :a => 'something') #=> ['something', nil, :c]
Example.class_method
b => nil, :a => 'something') #=> ['something',
nil, :c]
Example.other_class_method
b => nil, :a => 'something') #=>
['something', nil, :c]
Hosted at: http://github.com/maca/arguments/tree/master
Macario
1.9.1. I think is a good alternative to traditional options hash, usage
is as follows:
require 'arguments'
class Example
def meth(a = :a, b = :b, c = :c)
[a,b,c]
end
class << self
def class_method(a = :a, b = :b, c = :c)
[a,b,c]
end
def other_class_method(a = :a, b = :b, c = :c)
[a,b,c]
end
named_args_for :class_method
end
named_args_for :meth, :'self.other_class_method'
end
nu = Example.new
nu.meth #=> [:a,:b,:c]
nu.meth(1, :c => Class) #=> [1,:b,Class]
nu.meth
Example.class_method
nil, :c]
Example.other_class_method
['something', nil, :c]
Hosted at: http://github.com/maca/arguments/tree/master
Macario