It´s better to wait for a productive programmer to become available than it is to wait for the first available programmer to become productive. — Steve McConnell What is ~/.irbrc file? 🔖 After work with multiple Rails , you might have some methods and preferred ways of working with them. apps i.e. you're using few generalized methods or configuration your IRB session(rails console) in a single project and want to have the same methods & configuration on other projects you’re working on, you can add those methods & configuration in your file. ~/.irbrc You can create file in your root directory if it’s not present. ~/.irbrc Things you can include in your ~/.irbrc file 🗄 Configurations which need to be used in all Rails Apps Methods which need to be used in all Rails Apps Require/load specific file(s) or Gem(s) Hacky convenience methods that help you play with your objects 🧮 My .irbrc file ActiveRecord::Base.logger.level = ?(ActiveRecord) IRB.conf[ ] = (methods - Object.instance_methods).sort .method(method_name).source_location file, line = .sl(method_name) file && line .method(method_name).source.display tempfile = File.join(Rails.root.join( ), SecureRandom.hex) File.open(tempfile, ) { f << .as_json} system( ) sleep( ) File.delete( tempfile ) history_array = Readline::HISTORY.to_a count = count > ? count : count > from = history_array.length - count history_array = history_array[from..- ] print history_array.join( ) puts load File.expand_path( ) reload! @script_console_running puts system( ) cur = Time.now result = print puts puts $last_benchmark = cur result q exit puts puts puts puts puts puts puts puts puts puts puts require 'irb/completion' require 'rubygems' 1 if defined :SAVE_HISTORY 1000 # Overriding Object class class Object # Easily print methods local to an object's class def lm end # look up source location of a method def sl (method_name) self rescue " not found" #{method_name} end # open particular method in vs code def ocode (method_name) self if `code -g ' : '` #{file} #{line} else "' ' not found :(Try .lm to see available methods" #{method_name} #{ .name} self end end # display method source in rails console def ds (method_name) self end # open json object in VS Code Editor def oo 'tmp' 'w' |f| self " " #{ } 'code' || 'nano' #{tempfile} 1 end end # history command def hist (count = ) 0 # Get history into an array # if count is > 0 we'll use it. # otherwise set it to 0 0 0 if 0 1 end "\n" end # copy a string to the clipboard def cp (string) `echo " " | pbcopy` #{string} "copied in clipboard" end # reloads the irb console can be useful for debugging .irbrc def reload_irb "~/.irbrc" # will reload rails env if you are running ./script/console if "Console Reloaded!" end # opens irbrc in vscode def edit_irb `code ~/.irbrc` if "code" end def bm # From http://blog.evanweaver.com/articles/2006/12/13/benchmark/ # Call benchmark { } with any block and you get the wallclock runtime # as well as a percent change + or - from the last run yield " seconds" #{cur = Time.now - cur} " ( % change)" #{(cur / $last_benchmark * ).to_i - } 100 100 rescue "" end # exit using `q` alias # all available methods explaination def ll '=============================================================================================================' 'Welcome to rails console. Here are few list of pre-defined methods you can use.' '=============================================================================================================' 'obj.sl(:method) ------> source location e.g lead.sl(:name)' 'obj.ocode(:method) ---> open method in vs code e.g lead.ocode(:name)' 'obj.dispsoc(:method) -> display method source in rails console e.g lead.dispsoc(:name)' 'obj.oo ---------------> open object json in vs code e.g lead.oo' 'hist(n) --------------> command history e.g hist(10)' 'cp(str) --------------> copy string in clipboard e.g cp(lead.name)' 'bm(block) ------------> benchmarking for block passed as an argument e.g bm { Lead.all.pluck(:stage);0 }' '=============================================================================================================' end How to search awesome .irbrc file created by other devs 📭 Just click on the following URL and it’ll list all files created by other developers, you can create your file and add everything you need if you find anything useful - ~/.irbrc GitHub https://gist.github.com/search?l=Ruby&q=irbrc References 📌 https://docs.ruby-lang.org/en/2.2.0/IRB.html https://www.justinweiss.com/articles/fast-consistent-setup-for-your-ruby-and-rails-projects/ https://github.com/kpumuk/dotfiles/blob/master/irbrc Found this post useful? please share to help others find it! Feel free to leave a comment below.