Project

General

Profile

Bug #13762 ยป test.rb

backus (John Backus), 07/24/2017 12:29 AM

 
# frozen_string_literal: true

class MyProxy < BasicObject
def initialize(target)
@target = target
end

undef_method :==
undef_method :!=
undef_method :!
undef_method :__id__
undef_method :equal?

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 [] == MyProxy.new([])
puts MyProxy.new([]) == []
puts MyProxy.new([]) == MyProxy.new([])
    (1-1/1)