Skip to content

Instantly share code, notes, and snippets.

@pbharadiya
Forked from rishiip/.irbrc
Created May 8, 2020 12:53
Show Gist options
  • Save pbharadiya/9206ccdb6cf191fcb4612bc0ad6a96ef to your computer and use it in GitHub Desktop.
Save pbharadiya/9206ccdb6cf191fcb4612bc0ad6a96ef to your computer and use it in GitHub Desktop.
This is my current irbrc file which contains lots of helpful things.
# ActiveRecord::Base.logger.level = 1
# IRB.conf[:ECHO] = false
# Overriding Object class
class Object
# Easily print methods local to an object's class
def lm
(methods - Object.instance_methods).sort
end
# look up source location of a method
def sl(method_name)
self.method(method_name).source_location rescue "#{method_name} not found"
end
# open particular method in vs code
def ocode(method_name)
file, line = self.sl(method_name)
if file && line
`code -g '#{file}:#{line}'`
else
"'#{method_name}' not found :(Try #{self.name}.lm to see available methods"
end
end
# display method source in rails console
def sd(method_name)
self.method(method_name).source.display
end
end
# Print History
def phist
puts Readline::HISTORY.to_a
end
# copy a string to the clipboard
def cp(string)
`echo "#{string}" | pbcopy`
puts "copied in clipboard"
end
# Get current logged-in user for selldo
def getcu
begin
last_lines = `tail -n 500 'log/development.log'`;nil
User.find(last_lines[(last_lines.rindex("logged_in_user:") + 15), 24])
rescue Exception => e
puts "Error in getting user - #{e.message}"
end
end
# Get client for currently loggedin user
def getc
begin
getcu.client
rescue Exception => e
puts "Error in getting user - #{e.message}"
end
end
# reloads the irb console can be useful for debugging .irbrc
def reload_irb
load File.expand_path("~/.irbrc")
# will reload rails env if you are running ./script/console
reload! if @script_console_running
puts "Console Reloaded!"
end
# opens irbrc in vscode
def edit_irb
`code ~/.irbrc` if system("code")
end
# exit using `q`
alias q exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment