-
Notifications
You must be signed in to change notification settings - Fork 3
/
irbrc
90 lines (73 loc) · 2.48 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Hat tip: Iain Hecker, for console_extensions, http://github.com/iain/osx_settings/blob/master/.irbrc
$: << File.expand_path(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ))
require "lib/irb_helpers"
console_extensions __FILE__ do
extend_console "rubygems"
extend_console "interactive_editor"
extend_console 'wirble' do
Wirble.init(:history_size => 10000)
Wirble.colorize
end
extend_console 'ap' do
alias pp ap
end
extend_console '#enable_trace #disable_trace' do
def enable_trace( event_regex = /^(call|return)/, class_regex = /IRB|Wirble|RubyLex|RubyToken/ )
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 and
classname.to_s !~ class_regex
}
return
end
def disable_trace
puts "Disabling method tracing"
set_trace_func nil
end
end
extend_console '#time' do
require 'benchmark'
def time(times = 1, &block)
ret = nil
Benchmark.bm { |x| x.report { times.times { ret = yield } } }
ret
end
class Benchmark::ReportProxy
def initialize(bm, iterations)
@bm = bm
@iterations = iterations
@queue = []
end
def method_missing(method, *args, &block)
args.unshift(method.to_s + ':')
@bm.report(*args) do
@iterations.times { block.call }
end
end
end
def compare(times = 1, label_width = 12)
Benchmark.bm(label_width) do |x|
yield Benchmark::ReportProxy.new(x, times)
end
end
end
extend_console '#local_methods #non_object_methods' do
class Object
# Return a list of methods defined locally for a particular object. Useful
# for seeing what it does whilst losing all the guff that's implemented
# by its parents (eg Object).
def local_methods(obj = self)
(obj.methods - obj.class.superclass.instance_methods).sort
end
def non_object_methods(obj = self)
(obj.methods - Object.instance_methods).sort
end
end
end
extend_console '#methods_for #method_lookup_path' do
require 'method_locator'
end
end
# .railsrc
load File.dirname(__FILE__) + '/.railsrc' if ( ENV['RAILS_ENV'] || defined?(RAILS_ENV) || defined?(Rails) )