From: Jason Roelofs Date: 2007-06-02T04:29:09+09:00 Subject: Re: nested methods don't really exist?! ------=_Part_10903_28211554.1180726149887 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline What fREW said. Show me a language that actually allows you to do this and I'll show you a language that is the definition of scoping issues. You've defined method #b *inside* of method #a, so it should only be callable when in method #a. Jason On 6/1/07, fREW wrote: > > On 6/1/07, 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 > > > > 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 > > ------=_Part_10903_28211554.1180726149887--