3 ms·
> To know which method is called, you need to know the class of the receiver and the method name Unless someone's been using metaclass trickery, eg. arra
by bct 19y ago
> To know which method is called, you need to know the class of the receiver and the method name
Unless someone's been using metaclass trickery, eg.
array = []
def array.length; "banana"; end
array.length # => "banana"
[].length # => 0
(you can do the same thing with []=, the example is just longer)
- mdemare 19y agoI'd argue that this involves changing the class of the receiver (I think that is what actually happens under the covers). Also, I think this would count as a mortal sin in production code (but a lot of fun nevertheless).