From: "Mauricio Fernández" Date: 2004-09-15T20:23:00+09:00 Subject: Re: Singleton method on object via define_method? On Wed, Sep 15, 2004 at 05:09:52PM +0900, Robert Klemme wrote: > >> o = Object.new > => # > >> class << o; class << self; def to_s ; "foo" end end end > => nil > >> class << o; class << self;to_s end end > => "foo" > >> class << o; class << self; class << self; end end end > => nil > >> class << o; class << self; to_s end end > => "#" It's using Module#to_s because the klass of the singleton class is no longer itself... Module#to_s ends up calling class << o; self.to_s end which you defined before. > Hm, well ok. But is there an equivalent without evil.rb, i.e. with > "normal" Ruby code? I know that you can access all kinds of internals if > you write an extension, but AFAIK you can't know whether there is a > singleton class or not. (I assume your last sentence if missing "... without an extension".) The case above (singletons of singletons) is the only one I can think of right now where you can always know if the singleton has been created or not. -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com