Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > (named|keyword) arguments gem

Reply
Thread Tools

(named|keyword) arguments gem

 
 
Macario Ortega
Guest
Posts: n/a
 
      08-07-2009

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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RubyGems 0.9.1 calling a gem with gem '<gem>' Austin 7873 Ruby 5 01-27-2007 10:05 PM
gem.cmd install RMagick-win32-1.9.2-mswin32.gem: Buffer error Clifford Heath Ruby 7 06-09-2006 07:02 PM
[GEM PATCH] allow gem to install bin file to different location Ara.T.Howard Ruby 0 10-26-2005 11:52 PM
ERROR: While executing gem ... (Gem::GemNotFoundException) Could not find rubygems-upodate (> 0) in the repository han Ruby 1 10-24-2005 10:28 PM
[ANN] Getopt-Declare 1.12 (gem/zip) and GGEnv (gem/zip) gga Ruby 0 07-18-2005 03:21 PM



Advertisments