(named|keyword) arguments gem

Discussion in 'Ruby' started by Macario Ortega, Aug 7, 2009.

  1. 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
    --
    Posted via http://www.ruby-forum.com/.
     
    Macario Ortega, Aug 7, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward Diener
    Replies:
    14
    Views:
    5,125
    Josiah Carlson
    Apr 6, 2004
  2. Fuzzyman
    Replies:
    2
    Views:
    315
    Fuzzyman
    Feb 22, 2005
  3. Peter Motzfeldt
    Replies:
    1
    Views:
    176
  4. Macario Ortega

    Named arguments gem

    Macario Ortega, Oct 27, 2008, in forum: Ruby
    Replies:
    12
    Views:
    235
    Macario Ortega
    Oct 29, 2008
  5. Roger Pack
    Replies:
    2
    Views:
    116
    Roger Pack
    Jan 4, 2010
Loading...

Share This Page