(named|keyword) arguments gem

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs