David Vallner
8/24/2006 9:31:00 PM
Christoffer Sawicki wrote:
> Dear Rubyists,
>
> def x() yield rescue :error end
>
> [ x { Integer(nil) }, x { Float(nil) }, x{ String(nil) } ]
> # => [0, :error, ""]
>
> Isn't that a bit inconsistent?
>
> Cheers,
>
Probably.
<rant>
But my Java-addled brain makes me make damn sure nulls / nils don't come
anywhere near I expect actual data, like into collections or numbers. If
you don't rely on automagical conversion to work, it can't bite you if
it doesn't. Just code explicitly.
</rant>
The to_foo and #Foo() type conversion methods being different always
confuses the heck of me, which is why I get paranoid around them. Does
anyone have a link to some rationale for and explanation of the difference?
David Vallner