Using .gemspec version in documentation / library / script
So, I recently wrote a bunch of ruby gems, and one thing I find convenient is to include the current version (as stated in the gemspec) in the rdoc
-generated documentation for my libraries and in the OptionParser
-generated sections --help
used by my scripts (which I distribute via gem). Anyway, I can make it easier for my users to figure out which version of the library / script they are currently using.
Is there a way to access the version I specify in my gemspec from ruby files in my directories lib/
or bin/
? This way I don't need to update it in multiple places at once - just in my gemspec.
I am currently generating my gemspecs manually, I have not jumped on the Rake train yet. If I can't do what I want with just what Rubygems give me, will there be a rake or other tool that allows me to do this?
source to share
There is no way, I don't think, because Rubygems is just an installation mechanism for Ruby libraries that don't have a predefined concept of versioning.
However, possible workarounds might involve using Gem.loaded_specs
to find which gems have been loaded:
Gem.loaded_specs["mygemname"].version.to_s #=> "1.2.3"
source to share