Issue #5484 has been updated by Denis de Bernardy.


Well, I originally reported it as a bug, since I got bit by it. I can't recall the context let alone the specifics.

Anyway... Feel free to close if you think this is to be expected (I'd argue it shouldn't...)
----------------------------------------
Feature #5484: regexp comparison bug
https://bugs.ruby-lang.org/issues/5484

Author: Denis de Bernardy
Status: Open
Priority: Low
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10]


Based on ri Regexp.eql?:

Equality---Two regexps are equal if their patterns are identical, they have
the same character set code, and their casefold? values are the same.

  /abc/  == /abc/x   #=> false
  /abc/  == /abc/i   #=> false
  /abc/  == /abc/n   #=> false
  /abc/u == /abc/n   #=> false

However:

>> a = Regexp.new("/foo")
=> /\/foo/
>> b = /\/foo/
=> /\/foo/
>> a == b
=> false

The only meaningful difference between the two is the exact source:

>> a.source
=> "/foo"
>> b.source
=> "\\/foo"

But I'd argue that a's source should be normalized to that of b, or vice-versa, since their string representations are identical.


-- 
http://bugs.ruby-lang.org/