2025-06-30

On code spelunking

notes from Jordan Raine’s RailsConf 2019 talk

“you dont need to know the answer, you just have to find it”

return list of methods implemented on a Class object

(Foo.new.methods - Object.new.methods).sort

locate where some_method exists

obj = SomeClass.new
obj.method(:some_method)
obj.method(:some_method).source_location

view method in terminal

obj.method(:some_method).source.display

some methods derive from ancestors with the call of super()

Post.new.method(:save).super_method
ActiveRecord::Supressor#save

Post.new.method(:save).super_method.super_method
ActiveRecord::Transactions#save

Post.new.method(:save).super_method.super_method.super_method
ActiveRecord::Validations#save

Post.new.method(:save).super_method.super_method.super_method.super_method
ActiveRecord::Persistence#save

when code spelunking…

1. ask a question

what's the difference between try and try!?

2. start with what you know

ex: look at `try` and `try!`` code

3. only read relevant code

skim 20 lines, read 6 lines