9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

$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

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?