Improve IRB (and fix it on mac OS X)
Irb, the interactive Ruby shell should be the Ruby developer’s best friend.
Anyway, with a few customization, we can still improve this tool. First, you will notice the backward search won’t work out of the box on Mac OS X. This is an issue with readline.
To fix this, add this to your ~/.editrc file :
bind "^R" em-inc-search-prev
Now you may use CTRL-R to Reverse-search your history.
Also, you may want to give a try to Wirble, which is used to colorize your IRB output.
At tech-angels, we also use Hirb to format the ActiveRecord outputs.
Finally, this is a common .irbrc file :
require 'rubygems'
require 'wirble'
require 'hirb'
Wirble.init
Wirble.colorize
# hirb (active record output format in table)
Hirb::View.enable
# IRB Options
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:EVAL_HISTORY] = 200
# Log to STDOUT if in Rails
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
#IRB.conf[:USE_READLINE] = true
# Display the RAILS ENV in the prompt
# ie : [Development]>>
IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_N => "[#{ENV["RAILS_ENV"].capitalize}]>> ",
:PROMPT_I => "[#{ENV["RAILS_ENV"].capitalize}]>> ",
:PROMPT_S => nil,
:PROMPT_C => "?> ",
:RETURN => "=> %s\n"
}
# Set default prompt
IRB.conf[:PROMPT_MODE] = :CUSTOM
end
# We can also define convenient methods (credits go to thoughtbot)
def me
User.find_by_email("me@gmail.com")
end
14 notes
POSTED Monday August 16th
-
ticwesunwai reblogged this from tech-angels
-
elgangofeo liked this
-
josefina-anglemyer liked this
-
clair-worrel liked this
-
h13ronim liked this
-
tech-angels posted this
