Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: e0ea4d474a
Fetching contributors…

Cannot retrieve contributors at this time

102 lines (86 sloc) 2.418 kb
# Print current Ruby version, detecting RVM/rbenv
lambda do
real_version = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
manager, version = if system "which rvm > /dev/null 2> /dev/null"
["RVM", `rvm current`.split("\n").last]
elsif system "which rbenv > /dev/null 2> /dev/null"
["rbenv", `rbenv version`.strip]
else
[nil, real_version]
end
if version =~ /system/
system_raw_version = `$(whereis ruby) --version`
system_major = system_raw_version[/ruby \d\.\d\.\d/].split.last
system_patch = system_raw_version[/patchlevel \d+/].split.last
version = version.sub(/system/, "system (#{system_major}-p#{system_patch})")
end
if version.scan(/\d\.\d\.\d-p\d+/).first != real_version
manager = "(#{manager} bypassed)"
version = real_version
end
puts "\e[1;4;36m" << [manager, "using", version].join(" ") << "\e[0m"
end[]
module Unbundler
def self.require_external_gem gem
if defined? Bundler
unless Bundler.require.map(&:name).include? gem
gems_dir = $LOAD_PATH.grep(%r{lib/ruby/gems/}).first.gsub(%r{(lib/ruby/gems/[^/]+)/.*$}, '\\1/gems')
Dir["#{gems_dir}/*"].to_a.each do |gem_path|
if File.basename(gem_path).gsub(/-(\d\.?)+$/, '') == gem
$LOAD_PATH << "#{gem_path}/lib"
require gem
return
end
end
raise LoadError
end
else
require gem
end
end
end
class Array
def self.toy n = 10
Array.new(n) { |i| i }.shuffle
end
end
class Hash
def self.toy n = 5
keys = (:a..:z).to_a.take(n).shuffle
values = Array.toy(n)
Hash[keys.zip(values)]
end
end
def quickbm(repetitions = 100, &block)
require 'benchmark'
Benchmark.bm do |bm|
bm.report { repetitions.times &block }
end
end
if RUBY_PLATFORM.include? "darwin"
# Copy to OS X clipboard
def copy(str)
IO.popen('pbcopy', 'w') { |f| f << str.to_s }
$?.exited?
end
# Paste from OS X clipboard
def paste
`pbpaste`
end
end
# Load if in Rails console
if ($0 == 'irb' && ENV['RAILS_ENV']) || ($0 == 'script/rails' && Rails.env) || (defined?(Rails) && Rails.env)
def change_log(stream)
if defined? ActiveRecord::Base
ActiveRecord::Base.logger = Logger.new stream
ActiveRecord::Base.clear_active_connections!
end
end
def show_log
change_log STDOUT
end
def hide_log
change_log nil
end
change_log STDOUT
end
Jump to Line
Something went wrong with that request. Please try again.