I recently opened up pry, ran this:
1 |
test = TestGem.new |
but got this:
1 |
NameError: uninitialized constant TestGem |
Not greatly helpful.
It turned out that, despite adding it to my Gemfile and running
1 |
bundle |
I still needed to require the file in pry.
However, the name of the file isn’t obvious if it’s not your own gem. E.g.
1 2 |
require 'guess_incorrect_gem_name' LoadError: cannot load such file -- guess_incorrect_gem_name |
Eventually it seemed to be correct:
1 2 |
require 'guess_gem_name' => true |
but this didn’t work:
1 2 |
test = GuessGemName.new NameError: uninitialized constant GuessGameName |
but by looking at the gem file name via:
1 |
ls ~/.rvm/gems/ruby-2.1.5/gems/gem_name/lib/gem_name/gemname.rb |
I eventually used:
1 |
require "gem_name/gemname" |
which worked. E.g.
1 2 |
test = GemName.new => #<GemName:0x007fc8aae926c0> |
This all seems a lot of guess work.
What I’d like to see (and I’m sure there must be a way of doing this but Google’ing and searching StackOverflow has not turned anything up) is something like this:
1 2 3 4 5 6 7 8 |
gem install gem_name pry gem_name.help > > # require with > require 'gem_name/gemname' > # use with > test = GemName.new |