-
Notifications
You must be signed in to change notification settings - Fork 17
/
pryrc
52 lines (43 loc) · 1000 Bytes
/
pryrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
# vim: ft=ruby
begin
require 'awesome_print'
rescue LoadError
warn "can't load awesome_print"
end
# Show arguments for the current method
class ArgsCommand < Pry::ClassCommand
match '!args'
group 'Inspector Gadgets'
description 'show arguments for the current method'
banner <<-BANNER
Usage: !args
Show arguments for the current method.
BANNER
def process
args = current_method.parameters.map do |arg|
{ arg[1] => target.eval(arg[1].to_s) }
end
puts "Method #{colorize(current_method_name)} was called with:"
pputs args
end
def current_method
method current_method_name
end
def current_method_name
target.eval '__method__'
end
# 36 = light blue
def colorize(str, color_code = 36)
"\e[#{color_code}m#{str}\e[0m"
end
def pputs(obj)
# do we have the 'awesome_print' gem?
if defined?(ap)
ap obj
else
puts obj
end
end
end
Pry::Commands.add_command ArgsCommand