Da tvrtok 09 Februr 2006 22:12 Mark Volkmann napsal:
> I'd never seen this before. Cool!
>

I saw this on some page about ruby idioms somewhere. Might have been the 
RubyGarden one. Or the RAA library interface design guidelines. I think those 
are very roughly a ripoff from Perl's, and I don't necessarily like them, and 
I didn't like this idiom at first. But then I saw this other snippet where 
the default parameters were used and suddenly it made Perfect Sense (tm). 


This is used all over the place in Rails, and the options hash is useful 
outside constructors too. I find it generally both more readable and 
comfortable to use than having multiple methods accept different combinations 
of parameters, especially since you get the perks of keyword arguments 
(arbitrary argument order) along. You might want to check for typos by being 
strict about what keys / combinations of keys you accept in the options hash, 
and convert the keys to symbols or vice versa depending on what you except.

> I think you can use
> attribs = DEFAULTS.merge(param)
> instead of
> attribs = DEFAULTS.dup.update(params)
>

*bangs head against wall*

I should really, really start reading ri output better. I knew about 
Hash#update, but I didn't actually go on and notice it's a synonym for 
Hash#merge! when I checked ri. D'oh!

David Vallner