Skip to content

Instantly share code, notes, and snippets.

@marian13
Created August 19, 2023 21:42
Show Gist options
  • Save marian13/512d1fd788a9587079724edb285d05c8 to your computer and use it in GitHub Desktop.
Save marian13/512d1fd788a9587079724edb285d05c8 to your computer and use it in GitHub Desktop.

Ruby Method Lookup Algorithm

class Human
end

class Person < Human
end

person = Person.new

Instance Method

BaseObject method_missing
Kernel method_missing
Object method_missing
Human method_missing
Person method_missing

BaseObject instance methods
Kernel instance methods
Object instance methods # 3.
Human instance methods # 2.
Person instance methods # 1.

person.hello

Class Method

BaseObject method_missing
Kernel method_missing
Object method_missing
Module method_missing
Class method_missing
Human class method_missing
Person class method_missing

BaseObject instance methods
Kernel instance methods
Object instance methods
Module instance methods
Class instance methods # 3.
Human class methods # 2.
Person class methods # 1.

Person.hello

TODO: modules, singletons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment