Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2758 > unrolled thread
| Started by | Iain Barnett <iainspeed@gmail.com> |
|---|---|
| First post | 2011-04-13 08:47 -0500 |
| Last post | 2011-04-13 09:53 -0500 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.ruby
colliding method names Iain Barnett <iainspeed@gmail.com> - 2011-04-13 08:47 -0500
Re: colliding method names Josh Cheek <josh.cheek@gmail.com> - 2011-04-13 08:59 -0500
Re: colliding method names Iain Barnett <iainspeed@gmail.com> - 2011-04-13 09:53 -0500
| From | Iain Barnett <iainspeed@gmail.com> |
|---|---|
| Date | 2011-04-13 08:47 -0500 |
| Subject | colliding method names |
| Message-ID | <851933FF-D199-4489-8663-0F6A7E8FD7DC@gmail.com> |
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
[toc] | [next] | [standalone]
| From | Josh Cheek <josh.cheek@gmail.com> |
|---|---|
| Date | 2011-04-13 08:59 -0500 |
| Message-ID | <BANLkTimCZaTNQ5aor3hVTNCdpwOm_XzbgQ@mail.gmail.com> |
| In reply to | #2758 |
[Note: parts of this message were removed to make it a legal post.]
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
>
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
[toc] | [prev] | [next] | [standalone]
| From | Iain Barnett <iainspeed@gmail.com> |
|---|---|
| Date | 2011-04-13 09:53 -0500 |
| Message-ID | <F22FB037-3C4B-4F0A-91E5-7CD177A0E3F5@gmail.com> |
| In reply to | #2760 |
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 Thanks, I'll have a play around with that. Much appreciated. Regards, Iain
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.ruby
csiph-web