Friday, 6 September 2013

How does Ruby allow method param defaults to be derived from earlier params?

How does Ruby allow method param defaults to be derived from earlier params?

In Ruby, params passed first in the list can be the used to define
defaults for later params.
class Buddy
def test opts, spec = opts[:red]
puts spec
end
end
n = Buddy.new
n.test( {:red => 3} )
What wizardry does this?
Are all params loaded serially? Is this behaviour only for proc, but not
lambda?

No comments:

Post a Comment