On Fri, Jan 22, 2010 at 12:22, Jason King <[email protected]> wrote:

> Only comment I have for you *Glenn* is that I can't see any reason for the
> conditional, and it's an ArgumentError not a TypeError that's thrown.  I
> think your method becomes simply:
>
> def represents_number?(s)
>
>   Float(s)
>
> rescue ArgumentError
>
>   return false
>
> end
>
>
I like this approach. As a bonus, you could always test some regexes in your
rescue clause there. That way you're still covered if your application has
some numeric strings that Float doesn't like, as in Greg's examples.

-- 
Nick Zadrozny

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to