Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2758 > unrolled thread

colliding method names

Started byIain Barnett <iainspeed@gmail.com>
First post2011-04-13 08:47 -0500
Last post2011-04-13 09:53 -0500
Articles 3 — 2 participants

Back to article view | Back to comp.lang.ruby


Contents

  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

#2758 — colliding method names

FromIain Barnett <iainspeed@gmail.com>
Date2011-04-13 08:47 -0500
Subjectcolliding 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]


#2760

FromJosh Cheek <josh.cheek@gmail.com>
Date2011-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]


#2764

FromIain Barnett <iainspeed@gmail.com>
Date2011-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