Hi --

On Fri, 1 Jun 2007, Artur Merke wrote:

> Hi,
>
> I've just encountered somehow strange (for me) behavior of nested
> methods in ruby:
>
> class A
>  def a
>    def b
>      print "bbb"
>    end
>  end
>
>  def c
>    b
>  end
> end
>
> irb(main):013:0> A.new.c
> bbb=> nil

I get:

   inner.rb:9:in `c': undefined local variable or method `b' for
   #<A:0x1ea244> (NameError) from inner.rb:13

with Ruby 1.8.6, because b doesn't get defined until a is called.

Can you reproduce exactly what you're doing, including Ruby version?


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)