From: Christoph Date: 2004-12-01T11:16:33+09:00 Subject: Re: singleton methods : when are they not permitted? Florian Gross schrieb: > itsme213 wrote: > >> Why no singleton methods on Symbol? >> >> Are there other objects that are also not allowed to have singleton >> methods? > > > Singleton methods can not be defined for "immediate" Objects. > Immediate Objects are stored directly by their id which means they are > very cheap to use. > > Immediate objects include all Fixnums, Symbols, true, false and nil > (but note that def true.foo; end will silently add the method directly > to TrueClass because there is guaranteed to be only one instance, > true, for it.) > You can also not add methods to Floats and Bignums (this is for > consistency with Fixnums), but this can be changed by overriding > Numeric#singleton_method_added (Miss)Applying syllogistic logic you can add singleton methods to Floats or Singletons you just have do deal with the exception either by changing Numeric#singleton_method_added or simply catching the exception x = 2.0 class << x def bla;end rescue end x.bla /Christoph