diff --git a/ruby/irbrc b/ruby/irbrc old mode 100755 new mode 100644 index 2afd40c..4bc90c6 --- a/ruby/irbrc +++ b/ruby/irbrc @@ -1,19 +1,5 @@ require 'irb/completion' -# 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 @@ -22,25 +8,4 @@ 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 +load "#{ENV['HOME']}/.rubyrc" if File.exist?("#{ENV['HOME']}/.rubyrc") diff --git a/ruby/pryrc b/ruby/pryrc index e2da235..8903fad 100644 --- a/ruby/pryrc +++ b/ruby/pryrc @@ -1,34 +1,4 @@ # vim FTW Pry.config.editor = 'vim' -# Repeat last command on enter -# https://github.com/pry/pry/issues/607 -Pry::Commands.command(/^$/, "repeat last command") do - _pry_.input = StringIO.new(Pry.history.to_a.last) -end - -# 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 - -# Ask for Apartment tenant -if defined?(Rails::Console) && defined?(Apartment) - available_tenants = Apartment.tenant_names.sort - default_tenant = available_tenants.first - - puts "Available tenants: #{available_tenants.join(',')}" - print "Select tenant (#{default_tenant}): " - tenant = gets.strip - - Apartment::Tenant.switch(available_tenants.include?(tenant) ? tenant : default_tenant) -end +load "#{ENV['HOME']}/.rubyrc" if File.exist?("#{ENV['HOME']}/.rubyrc") diff --git a/ruby/rubyrc b/ruby/rubyrc new file mode 100644 index 0000000..fcb0290 --- /dev/null +++ b/ruby/rubyrc @@ -0,0 +1,36 @@ +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 + +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 + +# Ask for Apartment tenant +if defined?(Rails::Console) && defined?(Apartment) + available_tenants = Apartment.tenant_names.sort + default_tenant = available_tenants.first + + puts "Available tenants: #{available_tenants.join(',')}" + print "Select tenant (#{default_tenant}): " + tenant = gets.strip + + Apartment::Tenant.switch!(available_tenants.include?(tenant) ? tenant : default_tenant) +end