Pit Capitain
8/13/2008 7:32:00 PM
2008/8/12 David A. Black <dblack@rubypal.com>:
> But if you want to have a hash
> that automatically inserts a hash for an unknown key, you can do:
>
> func = lambda {|h,k| h[k] = Hash.new(&func) }
> hash = Hash.new(&func)
David, hashes like this don't solve Josh's problem. He wants two
conflicting things:
1) param[:x][:y] should be false or nil, so that you can use it as a condition
2) you should be able to nest arbitrarily deep, for example param[:x][:y][:z]
If Josh really wanted to do that, he'd have to define FalseClass#[] or
NilClass#[], but as you have written he'd better change his data
structures.
Regards,
Pit