Issue #13083 has been updated by rafaelfranca (Rafael Fran=E7a).


The detailed situation.

Rails and other libraries and codebases rely on `/regex/.match?(nil)` to re=
turn false. This change is making that method to raise an error in that sit=
uation.

Changing this behavior on Ruby 2.7 means that applications will break becau=
se of this change.

This change also have dubious value. While it makes things consistent now i=
t require the callers to do one more check.

Code that before was:

     /foo/.match?(some_variable)

Need to become:

    some_variable && /foo/.match?(some_variable)

or

    /foo/.match?(some_variable) unless some_variable

If you ask me, I believe this change is good, but it doesn't require a brea=
king change. We can deprecate the old behavior and then in a next version r=
emove it.

The codebases can change their code, of course, but so they can change for =
any breaking change in Ruby. If we are being careful to not introduce break=
ing changes in Ruby, this change should also falls in that category in my o=
pinion. If we are ok with this breaking change, why not with others like fr=
ozen string as default? Both change will require changes to codebases and b=
oth changes have dubious value.

----------------------------------------
Feature #13083: {String|Symbol}#match{?} with nil returns falsy as Regexp#m=
atch{?}
https://bugs.ruby-lang.org/issues/13083#change-82424

* Author: kachick (Kenichi Kamiya)
* Status: Closed
* Priority: Normal
* Assignee: =

* Target version: =

----------------------------------------
Just for consistency

* patch: https://github.com/ruby/ruby/pull/1506
* spec: https://github.com/ruby/spec/pull/380

Currently behaves as ( ruby --version: ruby 2.5.0dev (2016-12-28 trunk 5722=
8) [x86_64-darwin16] )

~~~ ruby
'string'.__send__(:=3D~, nil) #=3D> nil
'string'.match(nil)         #=3D> TypeError: wrong argument type nil (expec=
ted Regexp)
'string'.match?(nil)        #=3D> TypeError: wrong argument type nil (expec=
ted Regexp)
:symbol.__send__(:=3D~, nil)  #=3D> nil
:symbol.match(nil)          #=3D> TypeError: wrong argument type nil (expec=
ted Regexp)
:symbol.match?(nil)         #=3D> TypeError: wrong argument type nil (expec=
ted Regexp)
/regex/.__send__(:=3D~, nil)  #=3D> nil
/regex/.match(nil)          #=3D> nil
/regex/.match?(nil)         #=3D> false
~~~


Expected to

~~~ruby
'string'.__send__(:=3D~, nil) #=3D> nil
'string'.match(nil)         #=3D> nil
'string'.match?(nil)        #=3D> false
:symbol.__send__(:=3D~, nil)  #=3D> nil
:symbol.match(nil)          #=3D> nil
:symbol.match?(nil)         #=3D> false
/regex/.__send__(:=3D~, nil)  #=3D> nil
/regex/.match(nil)          #=3D> nil
/regex/.match?(nil)         #=3D> false
~~~



-- =

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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>