Reading Source Code - Follow Up Tips

9 views
Skip to first unread message

Benjamin Wanicur

unread,
May 6, 2019, 10:02:03 PM5/6/19
to SD Ruby
I wanted to share a few things I forgot and recently learned about using IRB to explore source code.  

I should also mention that during my talk I did not use any project-wide fuzzy searching to find files.  I thought it would be more confusing if we did not see where the file was located in the file tree.  When exploring the gem I did make heavy use of project-wide searching to find methods, etc....

We have an even more efficient way of finding methods in the source code when we are playing around with code in IRB.


Here is an example:

# Opens IRB and loads the VCR gem (would be the same as opening IRB and immediately typing "require 'vcr'")
irb -r vcr

# Inside our IRB session we can find info about methods using the `method(...).source_location`
2.5.3 :007 > VCR.method(:use_cassette).source_location
 => ["/Users/benne/.rvm/gems/ruby-2.5.3/gems/vcr-4.0.0/lib/vcr.rb", 178]


Much thanks to Michael Cordell for pointing this IRB feature out.  He also wrote a good series about exploring / reading source code here:  https://blog.mikecordell.com/2017/01/29/reading-ruby-code-rom-preface.html



Reply all
Reply to author
Forward
0 new messages