--- !ruby/object:RI::ClassDescription attributes: [] class_methods: - !ruby/object:RI::MethodSummary name: new comment: - !ruby/struct:SM::Flow::P body: Classes in Ruby are first-class objects---each is an instance of class Class. - !ruby/struct:SM::Flow::P body: "When a new class is created (typically using class Name ... end), an object of type Class is created and assigned to a global constant (Name in this case). When Name.new is called to create a new object, the new method in Class is run by default. This can be demonstrated by overriding new in Class:" - !ruby/struct:SM::Flow::VERB body: " class Class\n alias oldNew new\n def new(*args)\n print "Creating a new ", self.name, "\\n"\n oldNew(*args)\n end\n end\n\n class Name\n end\n\n n = Name.new\n" - !ruby/struct:SM::Flow::P body: produces: - !ruby/struct:SM::Flow::VERB body: " Creating a new Name\n" - !ruby/struct:SM::Flow::P body: Classes, modules, and objects are interrelated. In the diagram that follows, the vertical arrows represent inheritance, and the parentheses meta-classes. All metaclasses are instances of the class `Class'. - !ruby/struct:SM::Flow::VERB body: " +------------------+\n | |\n Object---->(Object) |\n ^ ^ ^ ^ |\n | | | | |\n | | +-----+ +---------+ |\n | | | | |\n | +-----------+ | |\n | | | | |\n +------+ | Module--->(Module) |\n | | ^ ^ |\n OtherClass-->(OtherClass) | | |\n | | |\n Class---->(Class) |\n ^ |\n | |\n +----------------+\n" constants: [] full_name: Class includes: [] instance_methods: - !ruby/object:RI::MethodSummary name: allocate - !ruby/object:RI::MethodSummary name: inherited - !ruby/object:RI::MethodSummary name: new - !ruby/object:RI::MethodSummary name: superclass - !ruby/object:RI::MethodSummary name: to_yaml name: Class superclass: Module