Tim Hunter
5/28/2006 9:56:00 PM
Craig wrote:
> Thanks super! It works, but feels somewhat kludgy. It would be nice
> to have some sort of String#isnum? as a built-in.
> Craig
>
So, code it up yourself:
class String
def isnum?(s)
is = true
begin
Float(s)
rescue ArgumentError, TypeError
is = false
end
return is
end
end
Put that in a file called "mystuff.rb" and save mystuff.rb in one of the
directories Ruby looks for required files. Then at the top of every
program you want to use it, add
require 'mystuff'
Voila!