Class#initialize does not get called?

class Class
def initialize *args
super *args
p "init"
end
end

class AA
end

Shouldn’t my Class#initialize get called?

“Its Me” itsme213@hotmail.com schrieb im Newsbeitrag
news:zU2tc.148$mQ4.63@fe2.texas.rr.com

class Class
def initialize *args
super *args
p “init”
end
end

class AA
end

Shouldn’t my Class#initialize get called?

Probably not since class creation does a lot of magic behind the scenes.
However, there is a hook that might help you:

class Object
def self.inherited(cl)
puts “new class #{cl}”
end
end

class AA
end

class BB < AA
end

in irb:

class Object
def self.inherited(cl)
puts “new class #{cl}”
end
end
=> nil

?> class AA

end
new class AA
=> nil

?> class BB < AA

end
new class BB
=> nil

Regards

robert