From: gabriele renzi Date: 2005-10-27T06:52:03+09:00 Subject: Re: nested def's Daniel Sch�le ha scritto: > Hello *, > > and it seems to be ok, no warning no error at least > I remember reading (but dont ask me the article) > that nested functions are not allowed in ruby > is this something that has been changed or was this always > possible? > > thx, Daniel it has been possible for long time (I can't say "always" :) But they don't work as you may think, since nested method definition still define the method for the same "self", and are not pure functions that have local scope. See example for better explanation: irb(main):001:0> def a irb(main):002:1> def b irb(main):003:2> def c irb(main):004:3> p 'in c' irb(main):005:3> end irb(main):006:2> p 'in b' irb(main):007:2> end irb(main):008:1> p 'in a' irb(main):009:1> end => nil irb(main):010:0> b NameError: undefined local variable or method `b' for main:Object from (irb):10 irb(main):011:0> a "in a" => nil irb(main):012:0> b "in b" => nil