Robert Klemme
1/29/2009 12:56:00 PM
2009/1/29 Barun Singh <barunio@gmail.com>:
> I=F1aki Baz Castillo wrote:
>> El Jueves, 29 de Enero de 2009, Barun Singh escribi=F3:
>>>
>>> >> outputs "nil" to the screen
>>>
>>> Could someone explain why the eval statement returns an incorrect resul=
t
>>> for the regexp match? Thanks...
>>
>> It works if you escape the \ with \\ :
>>
>> eval %Q{'1' =3D~ /^[\\d]+$/}
>> =3D> 0
>>
>> Not sure why the \ must be escaped into a block code.
>
> Ah, thanks that worked. I wonder why extra escaping is needed just
> because it's in a block...
It's not a block - it's a doubly quoted string!
Ruby version 1.8.7
irb(main):001:0> %Q{foo}
=3D> "foo"
irb(main):002:0> %Q{foo}.class
=3D> String
irb(main):003:0> %Q{foo\\no}
=3D> "foo\\no"
irb(main):004:0> %Q{foo\no}
=3D> "foo\no"
irb(main):005:0> puts %Q{foo\no}
foo
o
=3D> nil
irb(main):006:0> puts %Q{foo\\no}
foo\no
=3D> nil
Kind regards
robert
--=20
remember.guy do |as, often| as.you_can - without end