Ruby is supposed to be truly adaptable, so good so far:
class Integer
def +(other)
self - other
end
end
puts 3 + 5
→ -2
But trying to go deeper doesn’t seem to work:
puts 2.__send__(:+, 3)
class BasicObject
def __send__(*args, **kwargs)
"I refuse"
end
end
puts 2 + 3
puts 2.__send__(:+, 3)
→
$ ruby override-basic-object-send.rb
5
override-basic-object-send.rb:4: warning: redefining `__send__' may cause serious problems
5
I refuse
So intrinsic method dispatch sidesteps BasicObject#__send__
?
Actually using puts
is similarly educational. Obviously none of the puts
call path is impacted.