Skip to content

Instantly share code, notes, and snippets.

@dekart
Created April 5, 2010 08:38
Show Gist options
  • Save dekart/356163 to your computer and use it in GitHub Desktop.
Save dekart/356163 to your computer and use it in GitHub Desktop.
# Put this to ~/.irbrc (no extension)
require "rubygems"
require 'irb/completion'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
# IRB & Readline hostory
module Readline
module History
LOG = "#{ENV['HOME']}/.irb-history"
def self.write_log(line)
File.open(LOG, 'ab') {|f| f << "#{line}\n" }
end
def self.start_session_log
write_log("\n# session start: #{Time.now}\n\n")
at_exit { write_log("\n# session stop: #{Time.now}\n") }
end
end
alias :old_readline :readline
def readline(*args)
ln = old_readline(*args)
begin
History.write_log(ln)
rescue
end
ln
end
end
Readline::History.start_session_log
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
IRB.conf[:PROMPT_MODE] = :SIMPLE
# IRB configuration reloading
def IRB.reload
load __FILE__
end
# Simple benchmarking
def time(times = 1)
require 'benchmark'
ret = nil
Benchmark.bm { |x| x.report { times.times { ret = yield } } }
ret
end
# Migration
def migrate(&block)
ActiveRecord::Migration.instance_eval(&block)
end
# SQL query execution
def sql(query)
ActiveRecord::Base.connection.select_all(query)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment