From: Phrogz Date: 2007-03-04T00:30:06+09:00 Subject: Re: define a function inside a method On Mar 3, 7:41 am, Olivier Renaud wrote: > I wrote a method which uses recursion, internally. As a test, I tried to > define the recursive function inside the method that is called : Time to investigate: class Foo def bar p jim rescue p "no jim yet" def jim; "jim"; end jim end end f1 = Foo.new p f1.jim rescue p "no jim yet" #=> "no jim yet" p f1.bar #=> "no jim yet" #=> "jim" p f1.jim #=> "jim" f2 = Foo.new p f2.jim #=> "jim" p f1.method( :jim ) #=> # What I deduce from this is that running Foo#bar causes a new instance method "jim" to be defined for the Foo class. The only thing this gets you is delayed method realization, once only, per class. It's not a private function for the use by that method only.