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
You can use #method
begin
method :foo # =>
rescue
$! # => #<NameError: undefined method `foo' for class `Object'>
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 Wed, Apr 13, 2011 at 8:47 AM, Iain Barnett <iainspeed@gmail.com> wrote:
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
Thanks, I'll have a play around with that.
Much appreciated.
Regards,
Iain
···
On 13 Apr 2011, at 14:59, Josh Cheek wrote:
You can use #method
begin
method :foo # =>
rescue
$! # => #<NameError: undefined method `foo' for class `Object'>
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