You are on page 1of 1

Ruby method

module Kernel module Kernel


def self.class_meth def inst_method lookup flow
# ... # ...
copyright 2006 Gavin Kistner
!@phrogz.net

class Object class Object


def self.class_meth def inst_method
# ... # ...
1

class Module class Module


def self.class_meth def inst_method
# ... # ...
core ruby objects

class Class class Class module Polygon module Polygon


def self.class_meth def inst_method def self.class_meth def inst_method
# ... # ... # ... # ...
2 3

class Rect
include Polygon
end
class Rect class Rect
def self.class_meth def inst_method
# ... # ...
module Regular module Reguiar
def self.class_meth def inst_method
4 # ... # ...
class Square < Rect class Square < Rect
def self.class_meth def inst_method class Square
# ... # ... include Regular
end

def square1.meth
#just square1 key
end
classes
modules
square1.do_it( ) square2.do_it( ) instances

1 All method lookups end up at the instance 3 Including a module in a class only pulls in the
methods of Object (which includes Kernel). instance methods, not the class methods.
This includes class methods of user classes. (Using extend instead would cause the class to
inherit class methods from the instance methods
of the module.)

2 User classes inherit class methods from the 4 Including a module in a sub class can 'shadow'
instance methods on the Class class, after methods from the parent class, as the module is
going through class methods of Object. searched before the parent.

You might also like