Ruby
Rails

Gemfile に含まれてない gem を rails console で require する方法

More than 1 year has passed since last update.

$LOAD_PATH に lib/ までのフルパスを突っ込めばよい。

$ gem which benchmark/ips
/Users/kyanny/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/benchmark-ips-2.6.1/lib/benchmark/ips.rb

$ be rails c
Loading development environment (Rails 4.1.14)
[1] pry(main)> require 'benchmark/ips'
LoadError: cannot load such file -- benchmark/ips
from /Users/kyanny/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.1.14/lib/active_support/dependencies.rb:247:in `require'
[2] pry(main)> $: << '/Users/kyanny/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/benchmark-ips-2.6.1/lib/'; nil
nil
[3] pry(main)> require 'benchmark/ips'
true

元ネタ:
ruby on rails 3 - How to use a local gem in console with bundled environment - Stack Overflow
http://stackoverflow.com/questions/16463002/how-to-use-a-local-gem-in-console-with-bundled-environment