Actions
Bug #9581
closed`=~` defined on a subclass of `String` is sometimes ignored, and `String#=~` is called instead
Bug #9581:
`=~` defined on a subclass of `String` is sometimes ignored, and `String#=~` is called instead
Description
As is reported on StackOverflow (http://stackoverflow.com/questions/22103018) by Gabriel, overridden =~ on a subclass of String is sometimes ignored, and the original String#=~ is called. Particularly, when we have:
class MyString < String
def =~ re; :foo end
end
s = MyString.new("abc")
these give the correct result:
r = /abc/; s =~ r # => :foo
s.send(:=~, r) # => :foo
s.send(:=~, /abc/) # => :foo
but in this case, MyString#=~ is ignored, and String#=~ is called instead:
s =~ /abc/ # => 0
Actions