-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path.irbrc
67 lines (55 loc) · 1.71 KB
/
.irbrc
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# NOTE: Run `gem install awesome_print` for 'ap' library.
#-----------------------------------------------------------------------------
# identity
#-----------------------------------------------------------------------------
interpreter = (RUBY_DESCRIPTION rescue RUBY_VERSION)
puts "## #{interpreter}"
if RUBY_VERSION < '1.9'
begin
require 'rubygems'
rescue LoadError
warn '### RubyGems is not available!'
end
elsif RUBY_VERSION >= '3.0'
return
end
#-----------------------------------------------------------------------------
# appearance
#-----------------------------------------------------------------------------
require 'pp'
pretty_printer = 'pp'
begin
require 'ap'
pretty_printer = 'ap'
rescue LoadError
end
IRB::Irb.class_eval do
define_method :output_value do
__send__ pretty_printer, @context.last_value
end
end
#-----------------------------------------------------------------------------
# interaction
#-----------------------------------------------------------------------------
require 'irb/completion'
IRB.conf[:AUTO_INDENT] = true
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 10_000
#-----------------------------------------------------------------------------
# utility
#-----------------------------------------------------------------------------
class Object
# create bang methods to reveal method origins
methods.grep(/methods$/).each do |plural|
singular = plural.to_s.sub(/s$/, '').to_sym
singular = :method unless respond_to? singular
define_method "#{plural}!" do |*args|
Hash[
send(plural, *args).map do |name|
method = send(singular, name)
[method, method.source_location]
end
]
end
end
end