(named|keyword) arguments gem

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top