Colliding method names

Hi,

If I’m running irb and I run a method called foo, is there a way to
find out which foo was called? I’m getting some strange results and
wonder if there’s more than one method with the same name out there.

Any help is much appreciated.

Regards,
Iain

On Wed, Apr 13, 2011 at 8:47 AM, Iain B. [email protected]
wrote:

You can use #method

begin
method :foo # =>
rescue
$! # => #<NameError: undefined method foo' for classObject’>
end

def foo
end
method :foo # => #<Method: Object#foo>

def self.foo
end
method :foo # => #<Method: main.foo>

“hello world”.instance_eval do

method :foo # => #<Method: String(Object)#foo>

class String
def foo
end
end
method :foo # => #<Method: String#foo>

def self.foo
end
method :foo # => #<Method: “hello world”.foo>

end

On 13 Apr 2011, at 14:59, Josh C. wrote:

end
method :foo # => #<Method: String(Object)#foo>

end

Thanks, I’ll have a play around with that.

Much appreciated.

Regards,
Iain

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs