From: Mike Wilson Date: 2005-10-21T09:46:17+09:00 Subject: Re: Fun with function definitions On 10/20/05, Anders H�ckersten wrote: > Me and a friend realised earlier today that this is actually a legal > Ruby program: > foo(def foo(a=nil) > puts "hello" > end) > foo > > The fact that this works seems to be a side effect of Ruby's semantics > rather than an intended feature, but maybe it's actually useful to be > able to do this? I can't think of any (practical) use of it - > suggestions are welcome. > > Regards, > Anders > That's pretty interesting. It makes for some interesting recursion too :) irb(main):021:0> foo(def foo(a=nil) irb(main):022:2> puts a irb(main):023:2> a += 1 if not a.nil? irb(main):024:2> return a irb(main):025:2> end) nil => nil irb(main):026:0> foo(foo(foo(foo(foo(foo(1)))))) 1 2 3 4 5 6 => 7