views:

150

answers:

2

So, I've been writing a bunch of ruby gems recently, and one thing I would find convenient is to include the current version (as specified in the gemspec) in the rdoc-generated documentation for my libraries, and in the OptionParser-generated --help sections used by my scripts (which I'm distributing via gem). Any way I can make it easy for my users to figure out which version of library/script they're currently using.

Is there any way I can access the version I specify in my gemspec from the ruby files in my lib/ or bin/ directories? That way, I don't have to update it multiple places at once - just in my gemspec.

Currently I generate my gemspecs by hand, I haven't jumped on the Rake train yet. If I can't do what I want directly with only what rubygems gives me, would rake or another tool allow me to do this?

A: 

You might want to take a look at newgem gem - as it both generates appropriate directory layout and also a gemspec file (compatible with GitHub).

Marcin Gil
+1  A: 

There isn't a way, I don't think, because Rubygems is just an installation mechanism for Ruby libraries, which have no predefined notion of versioning.

However, possible workarounds could include using Gem.loaded_specs to find which gems have been loaded:

Gem.loaded_specs["mygemname"].version.to_s #=> "1.2.3"
Ben Alpert
+125, this worked perfectly!
rampion