In Ruby, Objects Don't Have Methods. How Method Lookup Actually Works.
Post · https://dev.to/smtahosin/in-ruby-objects-dont-have-methods-how-method-lookup-actually-works-31g9
A visual deep dive into Ruby's object model under the hood. Why objects store state but zero methods, how hidden eigenclasses work, and the real method lookup path.
First seen by Oriel on .
AI summary
The article explains Ruby method lookup through classes and eigenclasses, arguing that objects store state while methods reside in method tables along an ancestry chain.
- In CRuby, instances hold instance variables and a pointer to their class; the class method table stores shared method definitions.
- Defining a singleton method creates an eigenclass for that object, places the method there, and links the eigenclass to the object's regular class.
- Methods defined with `def self.recent` are singleton methods on class objects, which are themselves instances of `Class`.
- Lookup checks the receiver's eigenclass, prepended and included modules, its class and ancestors, then searches again for `method_missing` if needed.
- Tagged pointers represent small integers and singleton values without heap-allocating ordinary objects for them.
#ruby #object model #method lookup #metaprogramming
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Reactions
Total public reactions reported by the source; distinct from points and likes.
- DEV Community: 30, latest observation ; +24 over observed period since
Comments
Comment count reported by the source.
- DEV Community: 3, latest observation ; +3 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| DEV Community | 4825930 | https://dev.to/smtahosin/in-ruby-objects-dont-have-methods-how-method-lookup-actually-works-31g9 Read discussion |