From: ara.t.howard@... Date: 2006-11-30T08:10:17+09:00 Subject: Re: Wrong results using named arguments On Thu, 30 Nov 2006, Jason Vogel wrote: > Okay, I have a couple of questions. If I use the Hash approach, > > - How do I handle argument default values? def the_method opts = { :arg => 'default value', :another_arg => 'default value too' } > - How do I handle required vs. optional arguments? def the_method opts = { :a => 'default a', :b => 'default b', :c => nil } a = opts[:a] || opts['a'] # optional, they pass in nil b = opts[:b] || opts['b'] or raise "no b!" # required > - Provide some sort of clue to the calling routines what the argument > "names" are? def the_method opts = { :arg => 'default value', :another_arg => 'default value too' } > - Is there a way to enumerate the valid choices for values (e.g. colors > = [red,white,blue]) def the_method opts = { :a => %w( a b c ).first, :b => %w( d e f ).first } -a -- if you want others to be happy, practice compassion. if you want to be happy, practice compassion. -- the dalai lama