Forum: Ruby is_number function ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bd3a9ca8a116e0055e65dd2d6069c946?d=identicon&s=25 Todd S. (tdog)
on 2006-04-27 23:56
Is there a function in core ruby to determin if a variable is a number
or not?

something like @XX.is_numeric? or is_number(@XX)
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-04-28 00:00
(Received via mailing list)
On Apr 27, 2006, at 11:56 PM, Todd S. wrote:

> Is there a function in core ruby to determin if a variable is a number
> or not?
>
> something like @XX.is_numeric? or is_number(@XX)

1.is_a?(Numeric) # => true

-- Daniel
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-28 00:00
(Received via mailing list)
On Apr 27, 2006, at 4:56 PM, Todd S. wrote:

> Is there a function in core ruby to determin if a variable is a number
> or not?
>
> something like @XX.is_numeric? or is_number(@XX)

 >> "hello".is_a? Numeric
=> false
 >> 3.is_a? Numeric
=> true

Hope that helps.

James Edward Gray II
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-04-28 00:03
(Received via mailing list)
On Apr 27, 2006, at 5:58 PM, Daniel Harple wrote:

> 1.is_a?(Numeric) # => true

Or Numeric === 1
Bd3a9ca8a116e0055e65dd2d6069c946?d=identicon&s=25 Todd S. (tdog)
on 2006-04-28 00:55
Daniel Harple wrote:

> 1.is_a?(Numeric) # => true
>
> -- Daniel

Thank you.  I thought it was something to that effect.
Unfortunately it doesn't seem to work for me.


However I find that the above returns:

1.is_a(Numeric)
NoMethodError: undefined method `is_a' for 1:Fixnum
        from (irb):4
        from :0

while, 1.is_a? Numeric does indeed return true.
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-04-28 01:22
(Received via mailing list)
On 4/27/06, Todd S. <tgate@mypublic.net> wrote:
> However I find that the above returns:
>
> 1.is_a(Numeric)
> NoMethodError: undefined method `is_a' for 1:Fixnum
>         from (irb):4
>         from :0
>
> while, 1.is_a? Numeric does indeed return true.
>
>

Don't forget the question mark.
This topic is locked and can not be replied to.