Steve Conover
5/8/2006 8:51:00 PM
Hi everyone,
I have a strange problem mixing in methods with the same name into
Object and Array (and I'm assuming this is a more general issue than
just both those classes).
My code is something like this:
class Object
def zap
puts "in object"
end
end
class Array
def zap
puts "in array"
end
end
I'm recieving an object instance from another part of the code, and
when I check its class it's "Object:Array". First of all, what is
"Object:Array" as opposed to "Object" and "Array"?
Secondly, when I invoke myobj.zap, it prints "in object". What's weird
is that if I add in these debugging statements:
class Object
def zap
puts self.method(:zap).to_s
puts self.method(:zap).call
puts "in object"
end
end
It reports that it's the method instance from class Array, and invoking
"call" actually causes the Array.zap method to execute.
I'm at a loss, and am very curious about what's going on here. Any
ideas?
Regards,
Steve