ruby - Class's superclass and String's superclass -
class
has superclass module
, class, string
, has superclass object
. why it?
to clear, need check out object model of ruby :
classes, modules, , objects interrelated. in diagram follows, vertical arrows represent inheritance, , parentheses meta-classes. metaclasses instances of class class
.
+---------+ +-... | | | basicobject-----|-->(basicobject)-------|-... ^ | ^ | | | | | object---------|----->(object)---------|-... ^ | ^ | | | | | +-------+ | +--------+ | | | | | | | | module-|---------|--->(module)-|-... | ^ | | ^ | | | | | | | | class-|---------|---->(class)-|-... | ^ | | ^ | | +---+ | +----+ | | obj--->otherclass---------->(otherclass)-----------...
all questions can answered looking @ diagram above.
but class, "string", superclass "object". why it?
look otherclass
in diagram. hash
, string
, array
etc otherclass
.
in ruby, "class" has superclass "module"
that's how designed, again can answered diagram.
Comments
Post a Comment