colliding method names

I

Iain Barnett

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=
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

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
 
I

Iain Barnett

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

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

Much appreciated.

Regards,
Iain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top