Skip to content

Instantly share code, notes, and snippets.

@sumitasok
Created November 17, 2011 06:02
Show Gist options
  • Save sumitasok/1372480 to your computer and use it in GitHub Desktop.
Save sumitasok/1372480 to your computer and use it in GitHub Desktop.
irb tricks
# this code goes into .irbrc file in you home folder
require 'rubygems'
require 'wirble'
require 'awesome_print'
require 'hirb'
# color the ruby console
Wirble.init
Wirble.colorize
# prints the sql query and related details on to console
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
end
# color the Model(ActiveRecord::Base) output
unless IRB.version.include?('DietRB')
IRB::Irb.class_eval do
def output_value
ap @context.last_value,
:multiline => false,
:plain => false,
:indent => 2,
:color => {
:array => :white,
:bignum => :blue,
:class => :yellow,
:date => :greenish,
:falseclass => :red,
:fixnum => :blue,
:float => :blue,
:hash => :gray,
:nilclass => :red,
:string => :yellowish,
:symbol => :cyanish,
:time => :greenish,
:trueclass => :green
}
end
end
else # MacRuby
IRB.formatter = Class.new(IRB::Formatter) do
def inspect_object(object)
object.ai
end
end.new
end
# inorder to see ActiveRecord Table in mysql type view alternate between Hirb.enable(for the told view) and Hirb.disable(for the default view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment