From: dblack@... Date: 2006-10-12T04:13:33+09:00 Subject: Re: Singleton Class Constants Hi -- On Thu, 12 Oct 2006, ara.t.howard@noaa.gov wrote: > On Thu, 12 Oct 2006 jdance@gmail.com wrote: > >> >> class Object >> def singleton_class >> class << self; self; end >> end >> end > > fyi. i prefer > > class Object > def singleton_class &block > sc = class << self; self; end > block ? sc.module_eval(&block) : sc > end > end > > for it allows > > class C > singleton_class{ > attr 'a' > alias_method 'b', 'a' > } > end I prefer it without that, since that makes it deviate from the #class method, which it's otherwise precisely parallel to. I'd rather that singleton_class work like class than that it work like class_eval. Otherwise you've got a situation where all classes except singleton classes have to call class_eval, and I don't see any grounds for granting that privilege. (I know we've hashed through this before, and don't agree; I just wanted to summarize the dissident position :-) David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org