IRB Tricks

一.window下创建irbrc
创建环境变量:
IRBRC => C:\ruby\irbrc\\_irbrc 
 HOME  => C:\Documents and Settings\yourname

二.编辑C:\ruby\irbrc\_irbrc这个文件..
1.给IRB加上清屏功能:
  在irb里cls:
  IRB Tricks_第1张图片

2.以表格形式显示查询结果+时时显示SQL日志
IRB Tricks_第2张图片
3.pertty print 查询结果:
IRB Tricks_第3张图片
4.tail
IRB Tricks_第4张图片


.irbrc配置:
 puts "Hello Hooopo!"
require 'pp'
require 'hirb'
def cls
  system "cls"
end


def enable_hirb
  Hirb::View.enable
end

def disable_hirb
  Hirb::View.disable
end

def log_on
 IRB.conf[:IRB_RC] = Proc.new do
    logger = Logger.new(STDOUT)
    ActiveRecord::Base.logger = logger
    ActiveResource::Base.logger = logger
  end
end

def ppp model
  if model.is_a? Array
    model.each do |m|
      ppp m
    end
  else
    pp model.attributes if model.is_a? ActiveRecord::Base
  end
end

if ENV['RAILS_ENV']  
  enable_hirb
  log_on
  
  def tail
    RAILS_DEFAULT_LOGGER.instance_eval{puts @last_log_message}
  end 
end




http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick
 

你可能感兴趣的:(c,osx,Ruby,Rails,ActiveRecord)