Skip to content

Instantly share code, notes, and snippets.

@cpetschnig
Created April 13, 2011 09:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cpetschnig/917284 to your computer and use it in GitHub Desktop.
Save cpetschnig/917284 to your computer and use it in GitHub Desktop.
IRB customization: load wirble, looksee and awesome_print; cheat bundler
require 'rubygems'
@irb_extensions = []
def require_for_irb_with_fallback_for_bundler_constraints(gem_name, load_file = nil)
load_file ||= gem_name
begin
begin
require load_file
rescue LoadError => e
gem_paths = []
Gem.path.each do |sys_gem_path|
Dir[sys_gem_path + '/gems/*'].each do |gem_path|
gem_paths << gem_path if %r{#{gem_name}} =~ gem_path
end
end
if gem_paths.empty?
error = LoadError.new("It seems like #{gem_name} is not installed.")
class << error; def skip_backtrace?; true; end; end
raise error
end
load_path = gem_paths.sort_by(&:to_s).last + "/lib/#{load_file}.rb"
load load_path
end
yield if block_given?
@irb_extensions << gem_name
rescue Exception => err
msg = "Couldn't load #{gem_name}: #{err}"
msg << "\n#{err.backtrace[0..10].join("\n")}" unless err.respond_to?(:skip_backtrace?) && err.skip_backtrace?
warn msg
end
end
require_for_irb_with_fallback_for_bundler_constraints 'wirble' do
# start wirble (with color)
Wirble.init
Wirble.colorize
end
require_for_irb_with_fallback_for_bundler_constraints 'looksee' do
Looksee.default_width = 160
end
require_for_irb_with_fallback_for_bundler_constraints 'awesome_print', 'ap'
@ndbroadbent
Copy link

This is awesome! Thanks so much for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment