From: Greg Weeks Date: 2007-11-11T18:00:48+09:00 Subject: Re: bug in nested defs (?) Ryan Davis wrote: > On Nov 10, 2007, at 23:40 , Greg Weeks wrote: > >> not a class, then the method is a singleton method of the context >> object. > > not quite. see "Defining a Method" of the pickaxe ed 2 on page 330. I now see that you're right. The Pick-axe book explains everything: "A method definition using an unadorned method name within a class or module definition creates an instance method". Here, "within" means lexically within, not dynamically within. This explains my problem case: module Definer def def_foo def foo ; "foo" ; end # class method of User ! end end class User extend Definer def_foo end User.foo # works! User.new.foo # error! The def of foo is dynamically within User, but it is lexically within Definer. (The fact that it is nested doesn't matter.) Consequently, foo becomes an instance method of Definer. This also implies (correctly) that the foo method of y is a common method, not a singleton method. So I was wrong about that too. But I think I've got it now. Yippee! -- Posted via http://www.ruby-forum.com/.