From: Xavier Noria Date: 2008-08-30T12:52:12+09:00 Subject: Re: assignment operator that treats empty and nil as the same thing On Sat, Aug 30, 2008 at 5:00 AM, RichardOnRails wrote: > Maybe I can redeem myself: Matt gave you a great solution in reopening > the Hash definition. I recommend a minor improvement as follows: > > class Hash > alias_method "orig_fetch", "[]" > def [](what) > result = orig_fetch(what) > result = nil if result == '' > end > end In my view that's abusing open classes. Ruby has well-defined boolean semantics, and Hash#[] is a fundamental method. People have expectations about those ones. In this case I think it could be better just to program explicitly your particular logic, either by hand, or in an clear separate method set_if_blank(key, value). I believe that one may be added to Hash if it deserves it in your app.