mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
3ff762cc7c
commit
980bf94f02
4 changed files with 22 additions and 40 deletions
|
@ -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|
|
||||
|
|
24
object.c
24
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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue