From: timr Date: 2011-01-03T13:10:22+09:00 Subject: Re: 1.respond_to? :define_singleton_method # => true Hi Gary, But you can add singleton methods to nil and true, so the problem with adding singleton methods to Fixnum objects is not related to the fact that they have a predetermined object_id. >> def nil.new_method >> puts 'I am nil' >> end => nil >> nil.new_method I am nil => nil >> def 1.new_method >> puts 'I am one' >> end SyntaxError: compile error (irb):5: syntax error, unexpected tINTEGER def 1.new_method ^ (irb):7: syntax error, unexpected kEND, expecting $end from (irb):7 from :0 >> def true.new_method >> puts 'I am so true' >> end => nil >> true.new_method I am so true => nil On Jan 2, 12:32 pm, Gary Wright wrote: > >> Does anyone understand why Fixnum objects list this method but denies > >> knowing of it, when they are sent the message? > > > it's prolly to protect the coolness of integers & stuff, as from what i > > understand all the basic integers are pre-defined & immutable. > > Fixnums are not 'immutable' in that you can associate state with a Fixnum instance and change that state: > > class Fixnum >   attr_accessor :note > end > > 1.note = "the loneliest number" > 1.note = "the second natural number" > > The essential properties of a fixnum, the 'oneness' of 1, the 'twoness' of 2, are immutable in that those properties are associated with the unique identity of each fixnum instance and not with any state associated with the instance. > > It is my understanding that the prohibition on singleton methods is because there doesn't seem to be an efficient way to implement them for objects that are implicitly represented by their object id (fixnum, symbol, nil, true, false). > > Gary Wright