ruby-changes:53772
From: mame <ko1@a...>
Date: Mon, 26 Nov 2018 16:55:13 +0900 (JST)
Subject: [ruby-changes:53772] mame:r65989 (trunk): object.c: Deprecate Object#=~ and add NilClass#=~`
mame 2018-11-26 16:55:07 +0900 (Mon, 26 Nov 2018) New Revision: 65989 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65989 Log: object.c: Deprecate Object#=~ and add NilClass#=~` Object#=~ always returns nil. This behavior is not only unuseful but also troublesome because it may hide a type error. This change deprecates Object#=~. For compatibility, NilClass#=~ is newly introduced. [Feature #15231] Modified files: trunk/NEWS trunk/object.c trunk/test/minitest/test_minitest_unit.rb Index: NEWS =================================================================== --- NEWS (revision 65988) +++ NEWS (revision 65989) @@ -217,6 +217,12 @@ sufficient information, see the ChangeLo https://github.com/ruby/ruby/blob/trunk/NEWS#L217 * NameError.new accepts +:receiver+ option to set receiver in Ruby code. [Feature #14313] +[NilClass] + + [New methods] + + * NilClass#=~ is added for compatibility. [Feature #15231] + [NoMethodError] [New options] @@ -447,6 +453,10 @@ sufficient information, see the ChangeLo https://github.com/ruby/ruby/blob/trunk/NEWS#L453 File.readlines do not invoke external commands even if the path starts with the pipe character <code>'|'</code>. [Feature #14245] +[Object] + + * Object#=~ is deprecated. [Feature #15231] + === Stdlib compatibility issues (excluding feature bug fixes) * These standard libraries have been promoted to default gems. Index: test/minitest/test_minitest_unit.rb =================================================================== --- test/minitest/test_minitest_unit.rb (revision 65988) +++ test/minitest/test_minitest_unit.rb (revision 65989) @@ -1528,7 +1528,9 @@ class TestMiniTestUnitTestCase < MiniTes https://github.com/ruby/ruby/blob/trunk/test/minitest/test_minitest_unit.rb#L1528 def test_refute_match_matcher_object @assertion_count = 2 - @tc.refute_match Object.new, 5 # default #=~ returns false + non_verbose do + @tc.refute_match Object.new, 5 # default #=~ returns false + end end def test_refute_match_object_triggered Index: object.c =================================================================== --- object.c (revision 65988) +++ object.c (revision 65989) @@ -1479,6 +1479,19 @@ nil_inspect(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1479 return rb_usascii_str_new2("nil"); } +/* + * call-seq: + * nil =~ other -> nil + * + * Dummy pattern matching -- always returns nil. + */ + +static VALUE +nil_match(VALUE obj1, VALUE obj2) +{ + return Qnil; +} + /*********************************************************************** * Document-class: TrueClass * @@ -1673,6 +1686,7 @@ rb_false(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1686 static VALUE rb_obj_match(VALUE obj1, VALUE obj2) { + rb_warning("Object#=~ is deprecated; it always returns nil"); return Qnil; } @@ -4149,6 +4163,7 @@ InitVM_Object(void) https://github.com/ruby/ruby/blob/trunk/object.c#L4163 rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0); rb_define_method(rb_cNilClass, "to_h", nil_to_h, 0); rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0); + rb_define_method(rb_cNilClass, "=~", nil_match, 1); rb_define_method(rb_cNilClass, "&", false_and, 1); rb_define_method(rb_cNilClass, "|", false_or, 1); rb_define_method(rb_cNilClass, "^", false_xor, 1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/