Skip to content

Different Regexp behavior from MRI #2905

Closed
@nirvdrum

Description

@nirvdrum

It looks like somewhere between 1.9.3 and 2.2.2, MRI changed its behavior around overriding String#=~. JRuby 9.0.0.0.pre2 special-cases this behavior in:

https://github.com/jruby/jruby/blob/9.0.0.0.pre2/core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java#L577-L579

It looks like the correct behavior is to always do a dispatch to =~ to pick up any overrides.

E.g.,

MRI 2.2.2:

> ruby -v -e 'class String; def =~(regexp); :weird_value; end; end; p "a" =~ /./'
-e:1: warning: method redefined; discarding old =~
:weird_value

JRuby 9.0.0.0.pre2:

> bin/jruby -v -e 'class String; def =~(regexp); :weird_value; end; end; p "a" =~ /./'
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-04-30 ef1fc91 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-amd64]
0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions