From: "Brian Schröder" Date: 2004-12-03T02:22:07+09:00 Subject: Re: nested defs, what if... On Thu, 2 Dec 2004 23:57:09 +0900 Austin Ziegler wrote: > On Thu, 2 Dec 2004 23:44:08 +0900, Hugh Sasse Staff Elec Eng > wrote: > > This is too half-baked to be an RCR, but here goes... > > > > At the moment we cannot write > > > > class Thingy > > def somefunc > > def newfunc > > ... > > end > > end > > end > > irb(main):001:0> class Thingy > irb(main):002:1> def somefunc > irb(main):003:2> def newfunc > irb(main):004:3> end > irb(main):005:2> end > irb(main):006:1> end > irb(main):007:0> Thingy.instance_methods.grep(/func/) > => ["somefunc"] > irb(main):009:0> Thingy.new.somefunc > => nil > irb(main):010:0> Thingy.instance_methods.grep(/func/) > => ["newfunc", "somefunc"] > But where is this usefull? It seems only complicated and inefficent to me (Doesn't it create a new instance method on each call?): class A def a() def b() self end self end end ==>nil A.new.b NoMethodError: undefined method `b' for # from (irb):2 A.new.a ==># A.new.a.b ==># A.new.b ==># -- Brian Schr�der http://www.brian-schroeder.de/