# (named|keyword) arguments gem

**URL:** <https://www.ruby-forum.com/t/named-keyword-arguments-gem/173346>\
**Category:** Ruby\
**Created:** [August 7, 2009, 6:38am UTC](https://www.ruby-forum.com/t/named-keyword-arguments-gem/173346 "2009-08-07T06:38:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![macario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@macario](https://www.ruby-forum.com/u/macario)\
**Post date:** [August 7, 2009, 6:38am UTC](https://www.ruby-forum.com/t/named-keyword-arguments-gem/173346/1 "2009-08-07T06:38:19Z")

</div>

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: [GitHub - maca/arguments: You don't have to wait until Ruby 2.0 to get (named|keyword) arguments. Works with 1.8.6, 1.8.7 and 1.9.1. An alternative to options hash.](http://github.com/maca/arguments/tree/master)

Macario
