On Apr 15, 2006, at 08:22 PM, Daniel H. wrote:
It seems like every time I want to evaluate a possibly undefined
have to use defined? to see that it exists first, so I can’t simply
I can honestly say that I’ve never actually made a call to defined?,
in all the Ruby code I’ve written in the last 10+ months…
– if params[:range_start] > 3
This can be: if params[:range_start].to_i > 3. Using the to_i method
will return zero if :range_start isn’t in the params hash.
or something like it. I need to have
– if defined? params[:range_start] && params[:range_start] > 3
If you want to go this way, you could simply say:
if params[:range_start] && params[:range_start] > 3, but that’s
far more verbose than you need to be.
I can’t even have
– if params[:range_start].nil?
This works for me, on every Hash object I’ve ever tried it on. Are
you getting an exception when you do this?
This is really annoying - is there anyway to avoid this?
I’m thinking you’re doing something that’s not quite right. The
behavior you’re describing goes against everything I’ve seen, with
regard to how Ruby Hash objects work.