-
Notifications
You must be signed in to change notification settings - Fork 1
/
irbrc
50 lines (42 loc) · 1.39 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
#!/usr/bin/ruby
require 'irb/completion'
# Save History between irb sessions
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
# # Misc IRB settings
IRB.conf[:USE_READLINE] = true # fixes behaviour of delete and backspace keys - see https://gist.github.com/3623012 on how to install readline with rbenv
IRB.conf[:AUTO_INDENT] = false # automatically indent code on multiple lines
IRB.conf[:PROMPT_MODE] = :SIMPLE # actually it doesn't make any difference if the dynamic prompt is enabled
class Object
# list methods which aren't in superclass
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