Actions
Bug #13762
closedChange in `#==` in Ruby 2.4?
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Description
Given this code:
# frozen_string_literal: true
class MyProxy < BasicObject
def initialize(target)
@target = target
end
undef_method :==
def method_missing(method_name, *args, &block)
if target_respond_to?(method_name)
@target.__send__(method_name, *args, &block)
else
::Object
.instance_method(method_name)
.bind(@target)
.call(*args, &block)
end
end
private
def target_respond_to?(method_name)
::Object
.instance_method(:respond_to?)
.bind(@target)
.call(method_name, true)
end
end
puts 'a' == MyProxy.new('a')
puts MyProxy.new('a') == 'a'
puts MyProxy.new('a') == MyProxy.new('a')
The output differs depending on the Ruby version:
$ chruby 2.3.4
$ ruby test.rb
true
true
true
$ chruby 2.4.1
$ ruby test.rb
false
true
false
Files
Actions
Like0
Like0