Skip to content

Instantly share code, notes, and snippets.

@wtaysom
Created December 19, 2011 10:51
Show Gist options
  • Save wtaysom/1496608 to your computer and use it in GitHub Desktop.
Save wtaysom/1496608 to your computer and use it in GitHub Desktop.
William's .pryrc
## _why inspired citizen428 delivered MethodFinder.
require_relative 'methodfinder_what'
## Pry Config
Pry.config.pager = false
Pry.config.editor = "mate -w"
Pry.config.prompt = [proc{"? "}, proc{"| "}]
# Making a custom output prompt is more trouble than one would expect.
Pry.output = SimpleDelegator.new(Pry.output)
class <<Pry.output
def puts(*args)
args[0] = args[0].sub(/^=> /, "") if args[0].kind_of? String
__getobj__.puts(*args)
end
end
Pry.config.commands.import(Pry::CommandSet.new do
## For quick loading.
$wl__reload_file = nil
command "reload", "Reload specified source file or previously reloaded file by default." do |file|
unless file
if $wl__reload_file
load($wl__reload_file)
next
end
files = Dir["*.rb"]
case files.size
when 0
output.puts "No Ruby files in #{Dir.pwd}"
next
when 1
file = files.first
else
output.puts "Many Ruby files in #{Dir.pwd}:"
output.puts files.map{|f| "\t#{f}"}
next
end
end
file = file.sub(/(\.rb)?$/, '.rb')
$wl__reload_file = file
load(file)
end
alias_command "r", "reload"
end)
## Useful Collections
def a
(1..6).to_a
end
def h
{hello: "world", free: "of charge"}
end
## Benchmarking
# Inspired by <http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick/123834#123834>.
def time(repetitions = 100, &block)
require 'benchmark'
Benchmark.bm{|b| b.report{repetitions.times(&block)}}
end
## Odds and Ends
def beep
putc ?\a
nil
end
# For choosing the first Anki flash card deck.
def d
rand(4) + 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment