-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Closed
Description
Common pattern for me is to inspect the source code of a method I'm curious about like so:
irb(main):018:0> Recording.find(904).children.method(:load).source_location
Recording Load (0.3ms) SELECT `recordings`.* FROM `recordings` WHERE `recordings`.`id` = 904 LIMIT 1
=> ["/Users/david/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/bundler/gems/rails-03e672a3daec/activerecord/lib/active_record/relation.rb", 513]
Then copy the path to the clipboard, then go to the console and do mate path
, then APPLE-G to jump to the line.
Let's make that simpler:
irb(main):018:0> puts Recording.find(904).children.method(:load).source_code
Recording Load (0.3ms) SELECT `recordings`.* FROM `recordings` WHERE `recordings`.`id` = 904 LIMIT 1
# Causes the records to be loaded from the database if they have not
# been loaded already. You can use this if for some reason you need
# to explicitly load some records before actually using them. The
# return value is the relation itself, not the records.
#
# Post.where(published: true).load # => #<ActiveRecord::Relation>
def load
exec_queries unless loaded?
self
end