When an instance of an object extends a module and extended is called on the module does the base already extend module?
module M
def self.extended base
# when this is called has base extended
end
def self.some_method
# that does something special ;)
end
end
obj = Object.new
obj.extend M
Update: Okay, so an Object and a String works, but why doesn’t numbers work? I get TypeError: can't define singleton
You cannot define a singleton on a Fixnum in ruby, because there is really only one of them (for each Fixnum). For example (in IRB):
Unlike strings, for example:
Obviously the specific numbers are going to vary on your system.
This makes sense, since there is no way for a particular “instance” of 73 to be different from any other “instance” of 73 (and I use the word “instance” loosely because it isn’t really an instance – they are all the same object).
http://ruby-doc.org/core-1.9.3/Fixnum.html