On 6/2/07, Robert Dober <robert.dober / gmail.com> wrote:
> On 6/2/07, Robert Klemme <shortcutter / googlemail.com> wrote:
>Actually the current state of
> > affairs is a queer mix, because the definition is nested but the scope
> > is not (they are neither restricted to the current instance nor to the
> > current method).
>
> Robert I think they are:
> # vim: sts=2 sw=2 expandtab nu tw=0:
>
> class A
>   def a
>     def b
>       42
>     end
>   end
>
> end
>
> p A.new.methods.grep(/^b$/)
> A.new.b
> []
> nested.rb:13: undefined method `b' for #<A:0xb7e337a0> (NoMethodError)
>
> Did you overlook David's post?
> I get exactly the same behavior than he does on a 1.8.5 Zenwalk
> I have the impression that OP got the victim of a "leftover" in his irb
> session.

Perhaps the OP was, but I think that Robert's statements are still correct:

$ cat innerdef.rb
class A
  def a
    def b
      42
    end
  end
end

puts "Using #{RUBY_VERSION}"
a = A.new
puts "Before invocation of a"
p a.methods & %w{a b}
p A.instance_methods(false)
a.a
puts "After invocation of a"
p a.methods & %w{a b}
p A.new.methods & %w{a b}
p A.instance_methods(false)

$ ruby innerdef.rb
Using 1.8.5
Before invocation of a
["a"]
["a"]
After invocation of a
["a", "b"]
["a", "b"]
["a", "b"]


-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/