On Fri, Jul 13, 2012 at 10:19 AM, Lars Haugseth
<[email protected]> wrote:
> If o is allowed to be a Fixnum, you need to cast to string first:
>
> /\A\d+\z/ === o.to_s
WTF? (That's the first time I remember me writing this here.)
Let me get that straight: you want to convert something which you
*know* is an integer to a String to check whether it is an integer?
If o is allowed to be an integer type then you would better check that
directly (e.g. with Integer === o). But it get's better:
irb(main):010:0> a=[1,1<<50,"1"]
=> [1, 1125899906842624, "1"]
irb(main):011:0> a.each {|x| y=Integer(x); printf "type %p converted
%p type %p\n", x.class, y, y.class}
type Fixnum converted 1 type Fixnum
type Bignum converted 1125899906842624 type Bignum
type String converted 1 type Fixnum
=> [1, 1125899906842624, "1"]
Cheers
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en