A bug in logical 'or' with regexp?

I am still using Ruby 1.6.8 and just came across a very strange thing

( nil || %r{abc} )

yields false no matter what regular expression you use, while,

( nil || 3)

yields 3, as it should.

Is it a known issue for 1.6.8? I checked that everything works fine in
1.8.1.

Here’s more information from irb:

[linux.gfbs:449]gfb-ems-session_1> ruby -v
ruby 1.6.8 (2002-12-24) [i686-linux]
[linux.gfbs:450]gfb-ems-session_1> irb
irb(main):001:0> nil || 3
=> 3 # OK
irb(main):002:0> nil || //
=> nil # WRONG
irb(main):003:0> nil || %r{abc}
=> nil # WRONG
irb(main):004:0> ( (nil) || (%r{abc}) )
=> nil # WRONG
irb(main):005:0> nil || “abc”
=> “abc” # OK
irb(main):006:0>

Thank you,
Gennady.

“Gennady” gfb@tonesoft.com schrieb im Newsbeitrag
news:40BE1DA0.9020409@tonesoft.com

I am still using Ruby 1.6.8 and just came across a very strange thing

( nil || %r{abc} )

( nil || %r{abc} )
=> /abc/

in 1.8.1 - I guess this is a log since fixed bug. Better not use 1.6.8 any
more. It’s really outdated.

robert
···

yields false no matter what regular expression you use, while,

( nil || 3)

yields 3, as it should.

Is it a known issue for 1.6.8? I checked that everything works fine in
1.8.1.

Here’s more information from irb:

[linux.gfbs:449]gfb-ems-session_1> ruby -v
ruby 1.6.8 (2002-12-24) [i686-linux]
[linux.gfbs:450]gfb-ems-session_1> irb
irb(main):001:0> nil || 3
=> 3 # OK
irb(main):002:0> nil || //
=> nil # WRONG
irb(main):003:0> nil || %r{abc}
=> nil # WRONG
irb(main):004:0> ( (nil) || (%r{abc}) )
=> nil # WRONG
irb(main):005:0> nil || “abc”
=> “abc” # OK
irb(main):006:0>

Thank you,
Gennady.

Hi,

At Thu, 3 Jun 2004 03:31:59 +0900,
Gennady wrote in [ruby-talk:102183]:

I am still using Ruby 1.6.8 and just came across a very strange thing

( nil || %r{abc} )

yields false no matter what regular expression you use, while,

( nil || 3)

yields 3, as it should.

Is it a known issue for 1.6.8? I checked that everything works fine in
1.8.1.

It was a deprecated feature. A mere regexp literal in logical
expression was automagically (in other words, in Perlish way)
treated as:

(nil || %r{abc} =~ $_)

···


Nobu Nakada

Thanks a lot, guys, for explanation. Now it all makes sense. We plan to move to 1.8.1, however it will not be easy as we embed Ruby interpreter into our executable and there are some issues with compatibility.

Gennady.

···

nobu.nokada@softhome.net wrote:

Hi,

At Thu, 3 Jun 2004 03:31:59 +0900,
Gennady wrote in [ruby-talk:102183]:

I am still using Ruby 1.6.8 and just came across a very strange thing

( nil || %r{abc} )

yields false no matter what regular expression you use, while,

( nil || 3)

yields 3, as it should.

Is it a known issue for 1.6.8? I checked that everything works fine in 1.8.1.

It was a deprecated feature. A mere regexp literal in logical
expression was automagically (in other words, in Perlish way)
treated as:

  (nil || %r{abc} =~ $_)