From: rafael@... Date: 2019-11-01T16:05:13+00:00 Subject: [ruby-core:95636] [Ruby master Feature#13083] {String|Symbol}#match{?} with nil returns falsy as Regexp#match{?} Issue #13083 has been updated by rafaelfranca (Rafael Fran�a). The detailed situation. Rails and other libraries and codebases rely on `/regex/.match?(nil)` to return false. This change is making that method to raise an error in that situation. Changing this behavior on Ruby 2.7 means that applications will break because of this change. This change also have dubious value. While it makes things consistent now it 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 breaking change. We can deprecate the old behavior and then in a next version remove 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 breaking changes in Ruby, this change should also falls in that category in my opinion. If we are ok with this breaking change, why not with others like frozen string as default? Both change will require changes to codebases and both changes have dubious value. ---------------------------------------- Feature #13083: {String|Symbol}#match{?} with nil returns falsy as Regexp#match{?} 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 57228) [x86_64-darwin16] ) ~~~ ruby 'string'.__send__(:=~, nil) #=> nil 'string'.match(nil) #=> TypeError: wrong argument type nil (expected Regexp) 'string'.match?(nil) #=> TypeError: wrong argument type nil (expected Regexp) :symbol.__send__(:=~, nil) #=> nil :symbol.match(nil) #=> TypeError: wrong argument type nil (expected Regexp) :symbol.match?(nil) #=> TypeError: wrong argument type nil (expected Regexp) /regex/.__send__(:=~, nil) #=> nil /regex/.match(nil) #=> nil /regex/.match?(nil) #=> false ~~~ Expected to ~~~ruby 'string'.__send__(:=~, nil) #=> nil 'string'.match(nil) #=> nil 'string'.match?(nil) #=> false :symbol.__send__(:=~, nil) #=> nil :symbol.match(nil) #=> nil :symbol.match?(nil) #=> false /regex/.__send__(:=~, nil) #=> nil /regex/.match(nil) #=> nil /regex/.match?(nil) #=> false ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: