Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Created January 15, 2013 17:44
Show Gist options
  • Save carlzulauf/4540420 to your computer and use it in GitHub Desktop.
Save carlzulauf/4540420 to your computer and use it in GitHub Desktop.
Example irbrc to show using rails or gem specific features when they are available.
require 'pp'
require 'bigdecimal'
File.join(ENV["PWD"],'lib').tap do |lib|
if File.directory?(lib)
$LOAD_PATH.unshift(lib) unless defined?(Rails)
end
end
class BigDecimal
@@auto_round = 3
def self.auto_round=(val)
@@auto_round = val
end
def inspect
round(@@auto_round).to_s
end
end
def r
require 'redis' unless defined?(Redis)
begin
Redis.current.tap(&:inspect) # needed to know if connection failed
rescue
Redis.current = Redis.new(:path => "/tmp/redis.sock")
end
end
if defined?(ActiveRecord::Base)
class ActiveRecord::Base
def self.sample
s = scoped
c = s.count
s.offset(rand(c)).first
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment