dotfiles/ruby/pryrc

35 lines
884 B
Plaintext
Raw Normal View History

2014-07-07 14:49:42 +02:00
# 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
2014-07-07 14:49:42 +02:00
# 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
2014-07-07 14:49:42 +02:00
puts "Available tenants: #{available_tenants.join(',')}"
print "Select tenant (#{default_tenant}): "
tenant = gets.strip
2014-07-07 14:49:42 +02:00
Apartment::Tenant.switch(available_tenants.include?(tenant) ? tenant : default_tenant)
2014-07-07 14:49:42 +02:00
end