Find file
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (55 sloc) 1.32 KB
# Autocomplete
require 'irb/completion'
IRB.conf[:PROMPT_MODE] = :SIMPLE
%w[rubygems interactive_editor].each do |g|
begin
require g
rescue LoadError
warn "- Might want to gem install #{g}"
end
end
# Prompt behavior
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
# History
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 10000
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
# Easily print methods local to an object's class
class Object
def local_methods(obj = self)
(obj.methods - obj.class.superclass.instance_methods).sort
end
# print documentation
#
# ri 'Array#pop'
# Array.ri
# Array.ri :pop
# arr.ri :pop
def ri(method = nil)
unless method && method =~ /^[A-Z]/ # if class isn't specified
klass = self.kind_of?(Class) ? name : self.class.name
method = [klass, method].compact.join('#')
end
system 'ri', method.to_s
end
end
def copy(str)
IO.popen('pbcopy', 'w') { |f| f << str.to_s }
end
def copy_history
history = Readline::HISTORY.entries
index = history.rindex("exit") || -1
content = history[(index+1)..-2].join("\n")
puts content
copy content
end
def paste
`pbpaste`
end
def quick(repetitions=100, &block)
require 'benchmark'
Benchmark.bmbm do |b|
b.report {repetitions.times &block}
end
nil
end