On 6/1/07, Artur Merke <am / artbot.de> 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
>
> class A
>   def b
>     print "BBB"
>   end
> end
> irb(main):019:0> A.new.c
> BBB=> nil
>
> my first thought was that method/function 'b' would be local to
> method 'a' in class A (like it would be in Pascal). But this is of
> course not
> the case, as the above example shows.
>
> Is suppose that method 'a' (re)defines  method 'b' every time it is
> called, therefore  using nested methods doesn't seem to be a
> good idea in ruby (better readability but much worse performance, esp.
> when 'b' isn't a oneliner)
>
>
> any comments?
>
>
>

I am not exactly a wizard, but I think that your issue is context.
You are trying to call methods that only exist in other methods.  This
should not be!  You have to either define it outside of the method and
then pass it in (or reference it inside) or redefine it. Does that
help at all?

-- 
-fREW