Skip to content

Instantly share code, notes, and snippets.

@midwire
Last active February 17, 2021 21:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save midwire/b0c5d1b2ea48eef89e8b68f70600ae00 to your computer and use it in GitHub Desktop.
Save midwire/b0c5d1b2ea48eef89e8b68f70600ae00 to your computer and use it in GitHub Desktop.
[My .pryrc] It's awesome! #ruby
require 'irb/completion'
begin
require 'awesome_print'
Pry.config.print = proc { |output, value| output.puts value.ai }
rescue LoadError => err
puts "no awesome_print :("
end
Pry.commands.alias_command 'wh', 'whereami'
if defined?(PryNav) || defined?(PryByebug) || defined?(PryDebugger)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
end
if defined?(PryByebug) || defined?(PryDebugger)
Pry.commands.alias_command 'f', 'finish'
end
if defined?(PryByebug)
Pry::Commands.command /^$/, 'repeat last command' do
_pry_.run_command Pry.history.to_a.last
end
end
if defined?(PryStackExplorer)
Pry.commands.alias_command 'ss', 'show-stack'
Pry.commands.alias_command 'fr', 'frame'
end
def what_methods(obj)
(obj.public_methods - Object.public_methods - Object.instance_methods).sort
end
def find_methods(obj, pattern)
methods = what_methods(obj)
methods.grep(pattern)
end
def wm(obj)
what_methods(obj)
end
def predicates(obj)
what_methods(obj).grep(/\?$/)
end
def locate(obj, method)
obj.method(method.to_sym).source_location
end
# Fix the retarded inability to look at the params hash in Pry sessions
def params
params.permit!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment