[前][次][番号順一覧][スレッド一覧]

ruby-changes:70712

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 3 Jan 2022 23:26:26 +0900 (JST)
Subject: [ruby-changes:70712] 980bf94f02 (master): Kernel#=~: delete

https://git.ruby-lang.org/ruby.git/commit/?id=980bf94f02

From 980bf94f022116308fb7f95f697a85dc24f5884a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Mon, 27 Jul 2020 14:54:46 +0900
Subject: Kernel#=~: delete

Has been deprecated since ebff9dc10e6e72239c23e50acc7d3cbfdc659e7a.
---
 lib/delegate.rb                     |  2 +-
 object.c                            | 24 ++----------------------
 spec/ruby/core/kernel/match_spec.rb | 32 +++++++++++++++++---------------
 spec/ruby/core/nil/match_spec.rb    |  2 +-
 4 files changed, 21 insertions(+), 39 deletions(-)

diff --git a/lib/delegate.rb b/lib/delegate.rb
index a5ae605e9ec..70d4e4ad1d0 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -44,7 +44,7 @@ class Delegator < BasicObject https://github.com/ruby/ruby/blob/trunk/lib/delegate.rb#L44
   kernel = ::Kernel.dup
   kernel.class_eval do
     alias __raise__ raise
-    [:to_s, :inspect, :=~, :!~, :===, :<=>, :hash].each do |m|
+    [:to_s, :inspect, :!~, :===, :<=>, :hash].each do |m|
       undef_method m
     end
     private_instance_methods.each do |m|
diff --git a/object.c b/object.c
index 49315c566cd..2c9cbe7403d 100644
--- a/object.c
+++ b/object.c
@@ -1214,6 +1214,8 @@ nil_inspect(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1214
  *     nil =~ other  -> nil
  *
  *  Dummy pattern matching -- always returns nil.
+ *
+ *  This method makes it possible to `while gets =~ /re/ do`.
  */
 
 static VALUE
@@ -1393,27 +1395,6 @@ rb_false(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1395
     return Qfalse;
 }
 
-
-/*
- *  call-seq:
- *     obj =~ other  -> nil
- *
- * This method is deprecated.
- *
- * This is not only useless but also troublesome because it may hide a
- * type error.
- */
-
-static VALUE
-rb_obj_match(VALUE obj1, VALUE obj2)
-{
-    if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) {
-        rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, "deprecated Object#=~ is called on %"PRIsVALUE
-                "; it always returns nil", rb_obj_class(obj1));
-    }
-    return Qnil;
-}
-
 /*
  *  call-seq:
  *     obj !~ other  -> true or false
@@ -4444,7 +4425,6 @@ InitVM_Object(void) https://github.com/ruby/ruby/blob/trunk/object.c#L4425
 
     rb_define_method(rb_mKernel, "nil?", rb_false, 0);
     rb_define_method(rb_mKernel, "===", case_equal, 1);
-    rb_define_method(rb_mKernel, "=~", rb_obj_match, 1);
     rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1);
     rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
     rb_define_method(rb_mKernel, "hash", rb_obj_hash, 0); /* in hash.c */
diff --git a/spec/ruby/core/kernel/match_spec.rb b/spec/ruby/core/kernel/match_spec.rb
index fbfc77f9597..6c81ed8256c 100644
--- a/spec/ruby/core/kernel/match_spec.rb
+++ b/spec/ruby/core/kernel/match_spec.rb
@@ -1,22 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/match_spec.rb#L1
 require_relative '../../spec_helper'
 
-describe "Kernel#=~" do
-  it "returns nil matching any object" do
-    o = Object.new
+ruby_version_is ''...'3.2' do
+  describe "Kernel#=~" do
+    it "returns nil matching any object" do
+      o = Object.new
 
-    suppress_warning do
-      (o =~ /Object/).should   be_nil
-      (o =~ 'Object').should   be_nil
-      (o =~ Object).should     be_nil
-      (o =~ Object.new).should be_nil
-      (o =~ nil).should        be_nil
-      (o =~ true).should       be_nil
+      suppress_warning do
+        (o =~ /Object/).should   be_nil
+        (o =~ 'Object').should   be_nil
+        (o =~ Object).should     be_nil
+        (o =~ Object.new).should be_nil
+        (o =~ nil).should        be_nil
+        (o =~ true).should       be_nil
+      end
     end
-  end
 
-  it "is deprecated" do
-    -> do
-      Object.new =~ /regexp/
-    end.should complain(/deprecated Object#=~ is called on Object/, verbose: true)
+    it "is deprecated" do
+      -> do
+        Object.new =~ /regexp/
+      end.should complain(/deprecated Object#=~ is called on Object/, verbose: true)
+    end
   end
 end
diff --git a/spec/ruby/core/nil/match_spec.rb b/spec/ruby/core/nil/match_spec.rb
index 2e2b5d1c1b0..bc1c591793d 100644
--- a/spec/ruby/core/nil/match_spec.rb
+++ b/spec/ruby/core/nil/match_spec.rb
@@ -2,7 +2,7 @@ require_relative '../../spec_helper' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/nil/match_spec.rb#L2
 
 describe "NilClass#=~" do
   it "returns nil matching any object" do
-    o = Object.new
+    o = nil
 
     suppress_warning do
       (o =~ /Object/).should   be_nil
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]