During last nights SEMI.rb meeting, we talk a bit about irb. I offered up my .irbrc file. So here it is. Feel free to include your own.
Just a few words. I usually put some output at the top of my configuration files (.profile, etc) that let's me know what's being loaded.
I've also broke down my .irbrc file into sections. Each section has a url and date that tells where I found the entry and what date I added/updated it into my .irbrc file.
=====
puts ".irbc local"
# require 'extensions/all'
# require 'active_support'
###############################################################################
# http://ruby.tie-rack.org/3/my-irbrc/
2007.07.09
###############################################################################
IRB_START_TIME = Time.now
ARGV.concat [ "–readline" ]
require 'pp'
require 'rubygems'
require 'duration'
require 'wirble'
require 'irb/completion'
require 'irb/ext/save-history'
IRB.conf[:PROMPT][:SHORT] = {
:PROMPT_C=>"%03n:%i* ",
:RETURN=>"%s\n",
:PROMPT_I=>"%03n:%i> ",
:PROMPT_N=>"%03n:%i> ",
:PROMPT_S=>"%03n:%i%l "
}
# Wirble.init(
# :skip_prompt => true,
# :skip_history => true
# )
Wirble.init
Wirble.colorize
at_exit { puts
Duration.new(Time.now - IRB_START_TIME) }
def clear
print "\033[H\033[2J"
end
###############################################################################
# IRB configuration.
###############################################################################
IRB.conf[:EVAL_HISTORY] = 100
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = File::expand_path("~/.irb_history")
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
# IRB.conf[:PROMPT_MODE] = :DEFAULT
IRB.conf[:PROMPT_MODE] = :SHORT
# ['irb/completion', 'rubygems', 'stringio'].each do |mod|
# IRB.conf[:LOAD_MODULES] << mod unless
IRB.conf[:LOAD_MODULES].include?(mod)
# end
###############################################################################
# http://project.ioni.st/post/963#post-963
2006.11.09
# m(Time.new) m(Time.new).size m(Time.new).grep(/utc/)
###############################################################################
module Kernel
def m(object)
ObjectMethods.new(
object.public_methods(false).sort
)
end
class ObjectMethods < Array
def inspect
puts self
end
end
end
###############################################################################
# pm: Print Methods 2006.11.15
# http://www.notsostupid.com/blog/2006/11/09/pm-print-methods/
#
# Example: pm "a" pm "a", :more pm "a", /down/ pm "a", /up/
###############################################################################
ANSI_RESET = "\033[0m"
ANSI_BOLD = "\033[1m"
ANSI_GRAY = "\033[1;30m"
ANSI_LGRAY = "\033[0;37m"
# ANSI_RESET = ""
# ANSI_BOLD = ""
# ANSI_GRAY = ""
# ANSI_LGRAY = ""
def pm(obj, *options) # Print methods
methods = obj.methods - (options.include
?(:more) ? [] : Object.methods)
filter = options.select {|opt| opt.kind_of? Regexp}.first
methods = methods.select {|name| name =~ filter} if filter
data = methods.sort.collect do |name|
method = obj.method(name)
args = "(" + case method.arity <=> 0
when 1
("a"..(?a + method.arity - 1).chr).to_a.join(", ")
when -1
("a"..(?a - method.arity - 1).chr).to_a.join(", ")
else
""
end + ")"
klass = $1 if method.inspect =~ /Method: (.*?)#/
klass = $1 if klass =~ /((.*?))/
[name, args, klass]
end
max_name_length = data.collect {|item| item[0].size}.max
max_args_length =
data.collect {|item| item[1].size}.max
data.each do |item|
print " #{ANSI_BOLD}#{item[0].rjust(max_name_length)}#{ANSI_RESET}"
print "#{ANSI_GRAY}#{item[1].ljust(max_args_length)}#{ANSI_RESET}"
print " #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n"
end
data.size
end