Kernel#=~: delete

Has been deprecated since ebff9dc10e.
This commit is contained in:
卜部昌平 2020-07-27 14:54:46 +09:00 committed by Nobuyoshi Nakada
parent 3ff762cc7c
commit 980bf94f02
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6
4 changed files with 22 additions and 40 deletions

View File

@ -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|

View File

@ -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 */

View File

@ -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
it "is deprecated" do
-> do
Object.new =~ /regexp/
end.should complain(/deprecated Object#=~ is called on Object/, verbose: true)
end
end
it "is deprecated" do
-> do
Object.new =~ /regexp/
end.should complain(/deprecated Object#=~ is called on Object/, verbose: true)
end
end

View File

@ -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