|
|
||
-------------------------------------------------- Class: Class < Module Classes in Ruby are first-class objects---each is an instance of class Class . 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 : class Class alias oldNew new def new(*args) print "Creating a new ", self.name, "\n" oldNew(*args) end end class Name end n = Name.new _produces:_ Creating a new Name 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'. ------------------ | | Object---->(Object) | ^ ^ ^ ^ | | | | | | | | ----- --------- | | | | | | | ----------- | | | | | | | ------ | Module--->(Module) | | | ^ ^ | OtherClass-->(OtherClass) | | | | | | Class---->(Class) | ^ | | | ---------------- ------------------------------------------------------------------------ Class methods: -------------- new Instance methods: ----------------- allocate, inherited, new, superclass
==== Class ==== クラスのクラス。より正確に言えば、個々のクラスはそれぞれメタクラスと呼 ばれる名前のないクラスをクラスとして持っていて、Class はそのメタ クラスのクラスです。この関係は少し複雑ですが、Ruby を利用するにあたっ ては特に重要ではありません。 クラスは、モジュールとは * インスタンスを作成できる * include による Mix-in ができない という違いがありますが、それ以外のほとんどの機能は Module から継 承されています。Module のメソッドのうち * Module#module_function [Module/module_function] * Module#extend_object [Module/extend_object] * Module#append_features [Module/append_features] は Class では未定義にされています。 ---- Singleton methods ---- new ---- Instance methods ---- allocate inherited new superclass ---- Singleton methods (inherited) ---- constants nesting ---- Instance methods (inherited) ---- < <= <=> == === =~ > >= __id__ __send__ _dump _load alias_method ancestors append_features attr attr_accessor attr_reader attr_writer autoload autoload? class class_eval class_variables clone const_defined? const_get const_missing const_set constants define_method display dup eql? equal? extend extend_object freeze frozen? hash id include include? included included_modules initialize initialize_copy inspect instance_eval instance_method instance_methods instance_of? instance_variable_get instance_variable_set instance_variables is_a? kind_of? marshal_dump marshal_load method method_added method_defined? method_missing method_removed method_undefined methods module_eval module_function name nil? object_id pretty_print pretty_print_cycle pretty_print_instance_variables private private_class_method private_instance_methods private_method_defined? private_methods protected protected_instance_methods protected_method_defined? protected_methods public public_class_method public_instance_methods public_method_defined? public_methods remove_class_variable remove_const remove_instance_variable remove_method respond_to? send singleton_method_added singleton_method_removed singleton_method_undefined singleton_methods taint tainted? to_a to_ary to_hash to_int to_s to_str type undef_method untaint
* はてなダイアリーキーワード:Class