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?

0


source to share


2 answers


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"

      

+1


source


You might want to take a look at the newgem gem - as it creates the appropriate directory layout as well as a gemspec file (GitHub compatible).



0


source







All Articles