From: Yehuda Katz Date: 2008-11-16T08:17:38+09:00 Subject: [ruby-core:19957] Re: Proposal: Method#get_args In our case, we're dealing with inbound web params, so the defaults are always strings. Sent from my iPhone On Nov 15, 2008, at 2:34 PM, "Roger Pack" wrote: >> We need the defaults to handle out-of-order defaults: >> def action(bar=1, baz=2); end >> Where we get {baz => 5} inbound. > > AFAIK this isn't possible in Ruby currently (though might work fine > with "simple" values like you said). > > Some notes: > > Note that order matters: > def action(bar=1, bar2 = bar1); end # valid but note that it needs > bar1 to work, and needs it first > > def action(bar2 = bar1, bar1=0); end # invalid > > And then the "edge cases" where definitions include assignment are > hard: > > def action(bar=1, baz=(hidden_variable=2), foo=2*baz); end > > which, if you are given bar and foo, you can't recreate easily that > hidden_variable == 2 > > What you want might be something along the lines of > object.__send_with_named_variables__ :action, :baz => 5 > though I'm not sure how it would work. > > With access to the AST you can write "wrappers" to methods [which > still wouldn't help with the hidden_variable fella, except raising if > you find it, but work besides that] [1]. > > Was there a plan for named parameters in 2.0? That might be the way > to go. > > > -=R > > [1] http://code.google.com/p/ruby-roger-useful-functions/wiki/NamedParameters >