From: Florian Gross Date: 2004-12-01T08:12:46+09:00 Subject: Re: singleton methods : when are they not permitted? 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. It also seems not to be possible to directly add methods to literals like this: (Not sure why -- maybe Ruby optimizes literals?) irb(main):014:0> def ("x").foo; end SyntaxError: compile error (irb):14: can't define singleton method for literals However this can be worked around trivially by using an expression instead: irb(main):015:0> def (("x")).foo; end => nil