Hi -- On Sat, 2 Jun 2007, Trans wrote: > > > On Jun 2, 7:55 am, "Robert Dober" <robert.do... / gmail.com> wrote: >> On 6/2/07, Robert Klemme <shortcut... / googlemail.com> wrote: >> >> >> >>>>> #b is defined only after #a has been invoked at least once. I cannot >>>>> think of a scenario where you would want this behavior. >> >>>> There are dynamic behavior scenarios such as memoize where it could be >>>> used. But such cases are pretty rare. So I agree. Unless inner defs >>>> are local to their outer def, akin to local variables, they really >>>> aren't very useful --being little more than a shortcut for (class << >>>> self; self; end).define_method(). >> >>> That's exactly what they are not. If at all they are a shortcut for >>> self.class.define_method(), i.e. methods defined that way a regular >>> instance methods. >> >>> I also think that for memoize and such other mechanisms are far more >>> useful than current Ruby nested methods. 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. >> >> Cheers >> Robert >> >> Maybe that is the major reason for them not being too >> >>> useful. >> >>> Kind regards >> >>> robert > > > Ah, so inner defs won't be allowed after all. Figures, I guess. Why > have useful syntax when you can throw an error? :/ They're allowed; they're just not executed until the enclosing method is executed. 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)