views:

206

answers:

2

Can I ask ruby or rubygems to use the latest gem regardless of its source?

As mentioned in the update to this question, it turns out that ruby is using an older github gem (hmcgowan-roo 1.3.5) over a newer rubyforge gem that was installed more recently (roo 1.3.6).

My suspicion is that the magic pixy (either ruby or rubygems) looks under "h" before looking under "r".

I can force the rubyforge one to be used by doing

gem "roo"

but is it possible to tell ruby/rubygems that I'm happy to use either hmcgowan-roo or roo, but I want the latest version?

A: 

You could possibly use the gem method to specify which one you want.

RubyGems Manual - Chapter 4

Robert Rouse
Like "gem 'roo'" in my question, or using some extra parameters?
Andrew Grimm
You can set the version you want with the gem command as well. Beyond that, I'm not sure if there is a way. I don't see anything in the manual.
Robert Rouse
+1  A: 

Nope, there's no way unfortunately. As far as RubyGems is concerned, they are not the same gem, so RubyGems is unable to automatically determine which is the latest version. For the purposes of paranoia, the require line should be considered non-deterministic if there isn't a call to the gem method and you have multiple versions of the same library installed.

In general, you want your calls to the gem method to be located in a different place from your requires anyways (this allows files to be lazy-loaded), so it's perfectly reasonable to have a frequently updated file that just executes a bunch of calls to the gem method to ensure you've got the right version of everything. Additionally, in production, you usually don't want to do "give me the latest version" because the latest version may have changed its API or renamed some methods or similar, and if you haven't tested against it, you don't know if it'll break. You should always be making sure that you're using a specific, known-to-work version of every third-party library.

As a library author, I usually give people about a one or two version heads-up if I'm going to make changes that will break older usage of the API. However, sometimes people don't update for awhile, and get caught by this. Fortunately most people are careful, and stage things. Don't be the guy that updates libraries directly in production without testing them. :-)

Bob Aman