I have the following in my application controller:
def is_number?(object)
true if Float(object) rescue false
end
and the following condition in my controller:
if mystring.is_number?
end
The condition is throwing an undefined method error. I’m guessing I’ve defined is_number in the wrong place…?
Create
is_number?Method.Create a helper method:
And then call it like this:
Extend
StringClass.If you want to be able to call
is_number?directly on the string instead of passing it as a param to your helper function, then you need to defineis_number?as an extension of theStringclass, like so:And then you can call it with: