Fork me on GitHub

From Siberia with love

Tip: edit source code from pry/irb

For a long time I’m using small snippet that opens your editor on line where needed method defined. Here is code extracted from my ~/.irbrc:

if RUBY_VERSION > '1.9'
  class Object
    def edit_method(method)
      file, line = self.send(:method, method.to_sym).source_location
      return if file.nil?

      if editor = ENV['EDITOR']
        system("#{editor} #{file} +#{line}")
      else
        puts 'No $EDITOR set'
      end
    end
  end
end
# Example:
require 'securerandom'; SecureRandom.edit_method(:uuid)

But if you are using pry it has this functionality already!

# Example:
require 'securerandom'; edit-method SecureRandom.uuid
blog comments powered byDisqus