Ryan Williams wrote:
> On 11/29/06, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
>>
>> Joel VanderWerf wrote:
...
>> def m opts = {}
>>    opts = DEFAULTS.merge(opts)
>>    p opts
>> end
>>
>> m :x => 5  # ==> {:x=>5, :y=>2}
>>
>> Note that #merge is non-destructive (unlike #update, aka #merge!), so it
>> doesn't affect DEFAULTS.
> 
> 
> In most cases I think it is best if you define DEFAULTS inline, as in:
> 
> def m opts = {}
>   opts = {:x => 1,
>           :y => 2}.merge(opts)
>   p opts
> end
> 
> That way it's closer to the call and thus more self-documenting, and you
> don't have to worry about naming a bunch of constants in your class.  The
> downside is you're newing up a new defaults hash in every method call, and
> executing any contained statements.

If you define default option hashes as constants, you can comment them 
and they will appear in RDOC output. RDoc is even smart enough to try to 
put the constant value (i.e. the defaults hash) in the doc.

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407