forked from ryanb/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirbrc
72 lines (60 loc) · 1.87 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
68
69
70
71
72
#!/usr/bin/ruby
puts 'start irbrc'
# enable readline for jruby
IRB.conf[:USE_READLINE] = true
IRB.conf[:SAVE_HISTORY] = 1000
# load up and initialize Wirble with some nice defaults
# begin
# require 'rubygems'
# # require 'interactive_editor'
# # require 'wirble'
# # Wirble.init
# # Wirble.colorize
# rescue LoadError => err
# warn "Couldn't load: #{err}"
# end
class Object
# list methods which aren't in superclass
def local_methods(obj = self)
return Object.instance_methods.sort if obj.instance_of?(Object) rescue nil
(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
def enable_trace( event_regex = /^(call|return)/, class_regex = /IRB|Wirble|RubyLex|RubyToken|ActiveSupport|ActionController/ )
puts "Enabling method tracing with event regex #{event_regex.inspect} and class exclusion regex #{class_regex.inspect}"
set_trace_func(Proc.new{|event, file, line, id, binding, classname| printf "[%8s] %30s %30s (%s:%-2d)\n", event, id, classname, file, line if event =~ event_regex && classname.to_s !~ class_regex})
end
def disable_trace
puts "Disabling method tracing"
set_trace_func nil
end
if ($0 == 'irb' && ENV['RAILS_ENV']) || ($0 == 'bin/rails' && Rails.env)
puts "load railsrc"
load File.dirname(__FILE__) + '/.railsrc'
end