Joern Akkermann
Joern Akkermann

Reputation: 3622

Ruby: Getting a gem's name for require

I just installed the unicode-gem, which is called "unicode" but I cannot require it with require "unicode".

There was a command to retreive the name of a gem you need for a require, but I forgot it and cannot find it with google.

How was this again?

Upvotes: 2

Views: 1247

Answers (1)

the Tin Man
the Tin Man

Reputation: 160551

It seems like that should be part of the gem spec., so I've been nosing around in some of the rubygems gem's modules to see if there was a way to programmatically find out the right require string. So far I haven't found anything. It seems like a hole to me; I've run into the problem you're talking about, and it's a pain. The gem-writers are the ones who know the string, so it should be in the *.gemspec file.

My recommendation is to run gem env at the command-line, and cd into the directories displayed for "GEM PATHS", then into the gems directory, followed by the directory for the gem in question. Inside that directory look for README or similar files and see what they say. If nothing is found run:

grep -r require *

then look through the results for likely candidate strings. If there's a "test" directory, change the "*" to "test" first, to reduce the results to more-likely hits.

For instance, the Net::SSH gem is called "net-ssh", but it's gem is required using net/ssh. Searching with grep showed a lot of instances of require 'net/ssh'.

Upvotes: 2

Related Questions