Let\'s say I want a method which will be called like this:
tiger = create_tiger( :num_stripes => 12, :max_speed => 43.2 )
tiger.num_stripes # will be 12
If you're using Rails (not just plain Ruby), a slightly shorter method is
def foo(options = {})
options.reverse_merge! { ... defaults ... }
end
This has the added advantage of allowing you to do multiple lines a tad bit more cleanly:
def foo(options = {})
options.reverse_merge!(
:some_default => true,
:other_default => 5
)
end