So, you’re writing a Ruby Gem with a command-line program or two, and
you want to support a --version
option. When that option is displayed,
obviously, your program will just emit the version and exit. Ideally, you
want to use the version number that’s in the Gem Specification file, so
you don’t have put the version string in multiple places. So, you have to
find your gem’s specification file at runtime and pull the data you want
from it.
I had a surprisingly difficult time searching for the canonical way to accomplish that task. I finally resorted to UTSL, at which point, all became clear.
The solution is to use a Gem::GemPathSearcher
class, an instance of which
is available via Gem::searcher
:
1 2 3 4 5 6 7 8 9 10 |
|
The GemPathSearcher
class is documented
here.
Or, you can just use the source, Luke.