ruby: improve irbrc and pryrc

master
Guillaume DOTT 2014-07-07 14:49:42 +02:00
parent beaee6ad26
commit 118cc7c36f
2 changed files with 72 additions and 3 deletions

45
ruby/irbrc 100644 → 100755
View File

@ -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

30
ruby/pryrc 100644
View File

@ -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