From: "David A. Black" Date: 2005-09-13T21:47:58+09:00 Subject: Re: confused by nested functions Hi -- On Tue, 13 Sep 2005, Devin Mullins wrote: > Blrgh! Thanks, Mark & David. I have been schooled. > >> My interpretation is that only >> methods whose definitions start in the outermost scope are made into >> private methods of Object. > > Indeed, that's my impression now, too. I also know now that the magical > top-level Object does not have a singleton class: > >> a = "" >> class << a; def foo; def y; puts 'yo'; end end end >> a.foo >> a.y >> "hello".y >> __END__ >> yo >> -:5: undefined method `y' for "hello":String (NoMethodError) > > or, well, act like it. You're not accessing the top-level object's singleton class there, though. What you'd want would be: $ ruby -e 'class << self; def x; p 1; end; end; x' 1 David -- David A. Black dblack@wobblini.net