A bug in logical 'or' with regexp?

G

Gennady

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.
 
R

Robert Klemme

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

( 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.
 
N

nobu.nokada

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} =~ $_)
 
G

Gennady

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.

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} =~ $_)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top