Trans
11/27/2007 2:02:00 PM
On Nov 26, 9:15 pm, Mr Magpie <gazmcghees...@yahoo.com.au> wrote:
> I suggest that to_i() and to_f() have an optional parameter added with
> the default value of 0 (for backwards compatibility).
>
> This would allow code like
>
> if astring.to_f(nil)
> # valid, so use it
> else
> # not a valid float, nil was returned, so handle error
> end
if (num = astring.to_f) == 0
# may or may not be valid
begin
num = Float(astring)
rescue
# not a valid float, nil was returned, so handle error
end
end
# valid num, so use it
You can wrap it in a "monkey patch" if you like.
T.