-
Notifications
You must be signed in to change notification settings - Fork 46
/
rubyrc
39 lines (31 loc) · 1.06 KB
/
rubyrc
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
#!/usr/bin/env ruby
# Shared code for irbrc/pryrc.
module RubyRC
extend self
# Pre-defined hash and array to experiment with.
# http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick/123847#123847
HASH = { :one => 1, :two => 2, :three => 3, :four => 4, :five => 5 }
ARRAY = %w[one two three four five]
# E.g.:
# 12:23:15 >>
# DEV 12:23:15 >>
PROMPT = proc { |x|
"#{[ (rails_console? ? Rails.env.first(3).upcase : nil), Time.now.strftime("%H:%M:%S") ].compact.join(' ')} #{x} "
} unless defined?(PROMPT)
# Quick benchmarking
# http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick/123834#123834
def bench(repetitions=100, &block)
require "benchmark"
Benchmark.bmbm do |b|
b.report {repetitions.times &block}
end
nil
end
def rails_console?
$0 == "script/rails" || # Rails 3.
$0 == "bin/rails" || # Rails 4.
$0 == "rails_console" # Rails 4 (or later?) with Spring.
end
end
# Load .railsrc for Rails.
load File.dirname(__FILE__) + "/.railsrc" if RubyRC.rails_console?