summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author卜部昌平 <[email protected]>2020-07-27 14:54:46 +0900
committerNobuyoshi Nakada <[email protected]>2022-01-03 22:33:38 +0900
commit980bf94f022116308fb7f95f697a85dc24f5884a (patch)
treed8aba1ceefd60650a4087fa822aea78c48be3133
parent3ff762cc7c40a6422264cf978edfe6a0940070f1 (diff)
Kernel#=~: delete
Has been deprecated since ebff9dc10e6e72239c23e50acc7d3cbfdc659e7a.
-rw-r--r--lib/delegate.rb2
-rw-r--r--object.c24
-rw-r--r--spec/ruby/core/kernel/match_spec.rb32
-rw-r--r--spec/ruby/core/nil/match_spec.rb2
4 files changed, 21 insertions, 39 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index a5ae605e9e..70d4e4ad1d 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -44,7 +44,7 @@ class Delegator < BasicObject
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 49315c566c..2c9cbe7403 100644
--- a/object.c
+++ b/object.c
@@ -1214,6 +1214,8 @@ nil_inspect(VALUE obj)
* 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)
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)
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 fbfc77f959..6c81ed8256 100644
--- a/spec/ruby/core/kernel/match_spec.rb
+++ b/spec/ruby/core/kernel/match_spec.rb
@@ -1,22 +1,24 @@
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 2e2b5d1c1b..bc1c591793 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'
describe "NilClass#=~" do
it "returns nil matching any object" do
- o = Object.new
+ o = nil
suppress_warning do
(o =~ /Object/).should be_nil