Created
April 28, 2012 21:49
-
-
Save seeRead/2522333 to your computer and use it in GitHub Desktop.
IRB setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Interactive Ruby console configuration | |
# use x = _ to assign to last output | |
# use 'method' to determine where a method is defined | |
# e.g. User.method(:acts_as_commentable) | |
IRB_START_TIME = Time.now | |
# Print to yaml format with "y" | |
require 'yaml' | |
# Pretty printing | |
require 'pp' | |
# Ability to load rubygem modules | |
require 'rubygems' | |
# Tab completion | |
require 'irb/completion' | |
# Save irb sessions to history file | |
require 'irb/ext/save-history' | |
# Not stdlib | |
require 'map_by_method' | |
require 'what_methods' | |
# For printing time in session | |
require 'duration' | |
# For coloration | |
require 'wirble' | |
# for ri | |
require 'ori' | |
# config: https://github.com/dadooda/ori/blob/master/README_RI_CORE.md | |
# Include line numbers and indent levels: | |
IRB.conf[:PROMPT][:SHORT] = { | |
:PROMPT_C=>"%03n:%i* ", | |
:RETURN=>"%s\n", | |
:PROMPT_I=>"%03n:%i> ", | |
:PROMPT_N=>"%03n:%i> ", | |
:PROMPT_S=>"%03n:%i%l " | |
} | |
IRB.conf[:PROMPT_MODE] = :SHORT | |
# Adds readline functionality | |
IRB.conf[:USE_READLINE] = true | |
# Auto indents suites | |
IRB.conf[:AUTO_INDENT] = true | |
# Where history is saved | |
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" | |
# How many lines to save | |
IRB.conf[:SAVE_HISTORY] = 1000 | |
# Turn turn on colorization, off other wirble wierdness | |
Wirble.init(:skip_prompt => true, :skip_history => true) | |
Wirble.colorize | |
# Quick benchmarking facility | |
# Based on rue's irbrc => http://pastie.org/179534 | |
def quick(repetitions=100, &block) | |
require 'benchmark' | |
Benchmark.bmbm do |b| | |
b.report {repetitions.times &block} | |
end | |
nil | |
end | |
# Return only the methods not present on basic objects | |
# or use myobj.ri //. :own | |
class Object | |
def own_methods | |
(self.methods - Object.instance_methods).sort | |
end | |
end | |
# Prints how long the session has been open upon exit | |
at_exit { puts Duration.new(Time.now - IRB_START_TIME) } | |
# SQL love | |
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER') | |
require 'logger' | |
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment