Thank you, it works.
How did you find the Integer method of class Kernel ?
I typed "ri Kernel", but I can't find any Kernel's class method.
2007/6/4, Farrel Lifson <farrel.lifson@gmail.com>:
> On 04/06/07, w wg <duzuike@gmail.com> wrote:
> > How to check if a string is a integer ?
>
> You can use either the String#to_i or Kernel#Integer methods
>
> irb(main):001:0> "1234".to_i
> => 1234
> irb(main):002:0> "123A".to_i
> => 123
> irb(main):003:0> "A123".to_i
> => 0
> irb(main):004:0> Integer("A1234")
> ArgumentError: invalid value for Integer: "A1234"
> from (irb):4:in `Integer'
> from (irb):4
> irb(main):005:0> Integer("1234A")
> ArgumentError: invalid value for Integer: "1234A"
> from (irb):5:in `Integer'
> from (irb):5
> irb(main):006:0> Integer("1234")
> => 1234
> irb(main):007:0>
>
> Farrel
>
>
--
--
WenGe Wang