From: Joel VanderWerf Date: 2002-12-18T11:27:44+09:00 Subject: Re: named parameters Greg Millam wrote: > As for combining the two - having default values for hash arguments > passed, that's quite a bit tricker. only way I can think of is > > def foo(params) > params["baz"] = "Baz" unless params["baz"] > params["bar"] = "beer" unless params["bar"] > ... > end > > The problem with this method is, if a programmer wants to pass 'nil' or > 'false' or any non-true value as an argument, the default values would > overwrite that. def foo(params) {:argA => "default A", :argB => "default B"}.update params end p foo(:argA=>nil) # ==> {:argA=>nil, :argB=>"default B"}