Created
December 15, 2010 16:27
-
-
Save sumskyi/742197 to your computer and use it in GitHub Desktop.
.irbrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm') | |
| begin | |
| $LOAD_PATH.concat Dir.glob('/home/vlad/.rvm/gems/ruby-1.9.3-p0@global/gems/*/lib') if RUBY_VERSION =~ /1.9.3/ # brutal hardcode | |
| require 'rvm' | |
| if defined?(::Bundler) | |
| #$LOAD_PATH.concat Dir.glob("#{ENV['rvm_ruby_global_gems_path']}/gems/*/lib") | |
| end | |
| rescue LoadError => e | |
| puts e.message | |
| # RVM is unavailable at this point. | |
| raise "RVM ruby lib is currently unavailable." | |
| end | |
| end | |
| IRB.conf[:PROMPT_MODE]=:CLASSIC | |
| #puts $LOAD_PATH.inspect | |
| unless RUBY_VERSION =~ /1.8.7/ | |
| require 'pry' | |
| Pry.start | |
| exit | |
| end | |
| require 'irb/completion' | |
| def load_gem(name, lib=nil, &block) | |
| lib = name unless lib | |
| #Gem.activate(name) | |
| require lib | |
| yield if block_given? | |
| rescue Exception => e | |
| puts "#{e.class}: run sudo gem install #{name}" | |
| end | |
| def rails? | |
| ENV.include?('RAILS_ENV') or $0 =~ /rails/ | |
| end | |
| load_gem 'wirble' do | |
| Wirble.init | |
| Wirble.colorize | |
| end | |
| load_gem 'hirb' do | |
| Hirb.enable | |
| end | |
| load_gem 'sketches' do | |
| Sketches.config :editor => 'vim' | |
| end | |
| # usage: ap object | |
| load_gem 'awesome_print', 'ap' # awesome_print gem | |
| # usage: lp object | |
| load_gem 'looksee' | |
| class Object | |
| def local_methods | |
| self.class.instance_methods(false).sort | |
| end | |
| end | |
| # или так | |
| #class Object | |
| # def local_methods(obj = self) | |
| # (obj.methods - obj.class.superclass.instance_methods).sort | |
| # end | |
| #end | |
| # найти багу с бандлером и рельсами если не стоят вышеуказанные гемы | |
| if rails? | |
| # Log to STDOUT if in Rails | |
| #if rails? && defined? RAILS_DEFAULT_LOGGER | |
| #end | |
| #if RAILS_DEFAULT_LOGGER | |
| puts '==rails==' | |
| require 'active_record' | |
| #RAILS_DEFAULT_LOGGER = Logger.new(STDOUT) unless RAILS_DEFAULT_LOGGER | |
| #end | |
| def sql(query) | |
| ActiveRecord::Base.connection.select_all(query) | |
| end | |
| # эта хуйня с логами и так включена и нужна для on/off | |
| def change_log(stream) | |
| ActiveRecord::Base.logger = Logger.new(stream) | |
| ActiveRecord::Base.clear_active_connections! | |
| end | |
| def show_log | |
| change_log(STDOUT) | |
| puts "SQL log enabled. Enter 'reload!' to reload all loaded ActiveRecord classes" | |
| end | |
| def hide_log | |
| change_log(nil) | |
| puts "SQL log disabled. Enter 'reload!' to reload all loaded ActiveRecord classes" | |
| end | |
| change_log STDOUT | |
| end | |
| # time { ... } # Код выполнится 1 раз | |
| # time(100) { ... } # Код выполнится 100 раз | |
| def time(times = 1) | |
| require 'benchmark' | |
| ret = nil | |
| Benchmark.bm { |x| x.report { times.times { ret = yield } } } | |
| ret | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment