diff --git a/ruby/irbrc b/ruby/irbrc old mode 100644 new mode 100755 index f8b2d91..2afd40c --- a/ruby/irbrc +++ b/ruby/irbrc @@ -1,7 +1,46 @@ require 'irb/completion' -require 'irb/ext/save-history' -IRB.conf[:SAVE_HISTORY] = 200 -IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history" +# interactive editor: use vim from within irb +begin + require 'interactive_editor' +rescue LoadError => err + warn "Couldn't load interactive_editor: #{err}" +end +# awesome print +begin + require 'awesome_print' +rescue LoadError => err + warn "Couldn't load awesome_print: #{err}" +end + +# configure irb IRB.conf[:AUTO_INDENT]=true + +# irb history +IRB.conf[:EVAL_HISTORY] = 1000 +IRB.conf[:SAVE_HISTORY] = 1000 +IRB.conf[:HISTORY_FILE] = File.expand_path("~/.irb_history") + +# load .irbrc_rails in rails environments +railsrc_path = File.expand_path('~/.irb-railsrc') +if (ENV['RAILS_ENV'] || defined? Rails) && File.exist?(railsrc_path) + begin + load railsrc_path + rescue Exception + warn "Could not load: #{ railsrc_path } because of #{$!.message}" + end +end + +class Object + def interesting_methods + case self.class + when Class + self.public_methods.sort - Object.public_methods + when Module + self.public_methods.sort - Module.public_methods + else + self.public_methods.sort - Object.new.public_methods + end + end +end diff --git a/ruby/pryrc b/ruby/pryrc new file mode 100644 index 0000000..e8ed354 --- /dev/null +++ b/ruby/pryrc @@ -0,0 +1,30 @@ +# vim FTW +Pry.config.editor = 'vim' + +# Toys methods +# See https://gist.github.com/807492 +class Array + def self.toy(n=10, &block) + block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1} + end +end + +class Hash + def self.toy(n=10) + Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})] + end +end + +if defined?(Rails) && Rails.env + require 'logger' + + if defined?(ActiveRecord) + ActiveRecord::Base.logger = Logger.new(STDOUT) + ActiveRecord::Base.clear_active_connections! + end + + if defined?(DataMapper) + DataMapper::Logger.new($stdout, :debug) + end + +end