-
Notifications
You must be signed in to change notification settings - Fork 0
/
irbrc
executable file
·63 lines (54 loc) · 1.15 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
require "rubygems"
puts "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE}) #{RUBY_PLATFORM}"
IRB.conf[:PROMPT_MODE] = :DEFAULT
# Quick and dirty benchmarking
#
# quick(10) { sleep 0.1 }
def quick(repetitions=100, &block)
require 'benchmark'
Benchmark.bmbm do |b|
b.report {repetitions.times &block}
end
nil
end
# Time command execution
#
# time { sleep 1 }
def measure_time
start = Time.now
result = yield
puts sprintf "Total: %.2fs", Time.now - start
result
end
# Method lookup http://github.com/oggy/looksee
#
# lp variable
begin
require 'looksee'
rescue LoadError => err
warn "Couldn't load Looksee: #{err}"
end
# Copy string to clipboard
#
# copy "hello"
def copy(str)
IO.popen('pbcopy', 'w') { |f| f << str.to_s }
end
# Copy irb history to clipboard
#
# copy_history
def copy_history
history = Readline::HISTORY.entries
index = history.rindex("exit") || -1
content = history[(index+1)..-2].join("\n")
puts content
copy content
end
# Paste clipboard as string
#
# x = paste
def paste
`pbpaste`
end
# Automatically load .railsrc
load File.dirname(__FILE__) + '/.railsrc' if $0 == 'irb' && ENV['RAILS_ENV']