M
Macario Ortega
Hi, I've written a small gem to pass named arguments to an existing
method using ruby2ruby. Here's the usage:
require 'named_arguments'
class Example
def instance_method(uno = 1, dos = 2, tres = 3, cuatro = 4)
[uno, dos, tres, cuatro]
end
def another_instance_method( a = :a, b = :b, c = :c)
[a,b,c]
end
named_args_for :instance_method, :another_instance_method
class << self
def class_method(uno = 1, dos = 2, tres = 3, cuatro = 4)
[uno, dos, tres, cuatro]
end
named_args_for :class_method
end
end
Example.new.instance_method( ne, :dos => :two, :tres => :three )
=> [ne,:two,:three,4]
Example.new.another_instance_method
=> [:a,:b,:c]
Example.class_method( :dos => :b, :cuatro => :d )
=> [1,:b,2,:d]
http://github.com/maca/namedarguments/tree/master/
method using ruby2ruby. Here's the usage:
require 'named_arguments'
class Example
def instance_method(uno = 1, dos = 2, tres = 3, cuatro = 4)
[uno, dos, tres, cuatro]
end
def another_instance_method( a = :a, b = :b, c = :c)
[a,b,c]
end
named_args_for :instance_method, :another_instance_method
class << self
def class_method(uno = 1, dos = 2, tres = 3, cuatro = 4)
[uno, dos, tres, cuatro]
end
named_args_for :class_method
end
end
Example.new.instance_method( ne, :dos => :two, :tres => :three )
=> [ne,:two,:three,4]
Example.new.another_instance_method
=> [:a,:b,:c]
Example.class_method( :dos => :b, :cuatro => :d )
=> [1,:b,2,:d]
http://github.com/maca/namedarguments/tree/master/