-
Notifications
You must be signed in to change notification settings - Fork 1
/
.irbrc
140 lines (112 loc) · 2.64 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
printf "irb"
IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_I => "> ",
:PROMPT_N => ".. ",
:PROMPT_S => ".. ",
:PROMPT_C => ".. ",
:RETURN => "= %s\n"
}
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:PROMPT_MODE] = :CUSTOM
IRB.conf[:HISTORY_FILE] = "~/.cache/irb_history"
IRB.conf[:SAVE_HISTORY] = 250
IRB.conf[:USE_READLINE] = true
%w[
rubygems
irb/completion
pp
].each do |path|
printf " #{path}"
begin
require path
rescue LoadError
printf "\e[1;31m!\e[0m"
end
end
def self.silence_active_record
if defined? ActiveRecord
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
end
result = yield
ActiveRecord::Base.logger = old_logger if old_logger
result
end
def self.benchmark(count = 1)
require 'benchmark'
result = nil
silence_active_record do
Benchmark.bm do |benchmark|
benchmark.report {
count.times {
result = yield
}
}
end
end
result
end
def self.profile(count = 1)
begin
require 'ruby-prof'
rescue LoadError
raise "RubyProf not installed. Install it with: gem install ruby-prof"
end
result = nil
silence_active_record do
RubyProf::FlatPrinter.new(
RubyProf.profile {
count.times {
result = yield
}
}
).print STDOUT, :min_percent => 1
end
result
end
def self.copy(thing)
string = (thing.is_a? String) ? thing : thing.inspect.gsub("\"","\\\"")
`echo -n "#{string}" | pbcopy`
thing
end
class Object
def local_methods
(methods - Object.instance_methods).sort
end
alias_method :methods!, :local_methods
end
if defined? Wirble
Wirble.init
Wirble::Colorize.colors = {
# delimiter colors
:comma => :white,
:refers => :white,
# container colors (hash and array)
:open_hash => :white,
:close_hash => :white,
:open_array => :white,
:close_array => :white,
# object colors
:open_object => :yellow,
:object_class => :light_blue,
:object_addr_prefix => :white,
:object_addr => :light_red,
:object_line_prefix => :red,
:close_object => :yellow,
# symbol colors
:symbol => :light_red,
:symbol_prefix => :light_red,
# string colors
:open_string => :light_green,
:string => :light_green,
:close_string => :light_green,
# misc colors
:number => :light_red,
:keyword => :light_red,
:class => :light_blue,
:range => :white,
}
Wirble.colorize
end
puts "\n#{RUBY_DESCRIPTION}"
# vim: filetype=Ruby