# A question about gem's ~\>

**URL:** <https://rubytalk.org/t/a-question-about-gems/57917>\
**Category:** ruby-talk\
**Created:** [28 March 2010 23:21 UTC](https://rubytalk.org/t/a-question-about-gems/57917 "2010-03-28T23:21:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Schlef](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@Albert\_Schlef](https://rubytalk.org/u/Albert_Schlef)\
**Post date:** [28 March 2010 23:21 UTC](https://rubytalk.org/t/a-question-about-gems/57917/1 "2010-03-28T23:21:30Z")

</div>

I have a question about RubyGems's "~\>". Sorry for asking this here.  
I've searched in their "manual", but it's like searching a needle in a  
haystack.

My question is simple:

My gem works only on Ruby 1.8 (that is, it doesn't work on Ruby 1.9 (and  
isn't supposed to)).

In my gem specification I have:

&nbsp;&nbsp;s.required\_ruby\_version = '~\> 1.8'

Is this correct? Or do I have to write '~\> 1.8.0' ?

Unfortunately, Ruby 1.9's 'gem' installs my gem. I want it to refuse to  
do this. I suspect that's because '~\> 1.8' includes all versions of Ruby  
till 2.0 (not including).

So haw can I tell RubyGems that my gem is for 1.8 only?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Rick\_DeNatale1](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@Rick\_DeNatale1](https://rubytalk.org/u/Rick_DeNatale1)\
**Post date:** [29 March 2010 00:35 UTC](https://rubytalk.org/t/a-question-about-gems/57917/2 "2010-03-29T00:35:32Z")

</div>

> I have a question about RubyGems's "~\>". Sorry for asking this here.  
> I've searched in their "manual", but it's like searching a needle in a  
> haystack.
> 
> My question is simple:
> 
> My gem works only on Ruby 1.8 (that is, it doesn't work on Ruby 1.9 (and  
> isn't supposed to)).
> 
> In my gem specification I have:
> 
> s.required\_ruby\_version = '~\> 1.8'

This says that the version must have a major version number of 1, and  
a minor version number \>= 8, so it will include 1.9.x

> Is this correct? Or do I have to write '~\> 1.8.0' ?

You need to specify some teeny version number. so

~\> 1.8.0  
or  
~\> 1.8.6

should work.

> **···**
>
> On Sun, Mar 28, 2010 at 7:21 PM, Albert Schlef \<albertschlef@gmail.com\> wrote:
> 
> --  
> Rick DeNatale
> 
> Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
> Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
> WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
> LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [1 April 2010 03:16 UTC](https://rubytalk.org/t/a-question-about-gems/57917/3 "2010-04-01T03:16:31Z")

</div>

> I have a question about RubyGems's "~\>". Sorry for asking this here.  
> I've searched in their "manual", but it's like searching a needle in a  
> haystack.

ri Gem::Version

ri Gem::Requirement

> My question is simple:
> 
> My gem works only on Ruby 1.8 (that is, it doesn't work on Ruby 1.9 (and  
> isn't supposed to)).
> 
> In my gem specification I have:
> 
> s.required\_ruby\_version = '~\> 1.8'
> 
> Is this correct? Or do I have to write '~\> 1.8.0' ?

~\> 1.8.0 is correct

> **···**
>
> On Mar 28, 2010, at 16:21, Albert Schlef wrote:
> 
> > Unfortunately, Ruby 1.9's 'gem' installs my gem. I want it to refuse to  
> > do this. I suspect that's because '~\> 1.8' includes all versions of Ruby  
> > till 2.0 (not including).
> > 
> > So haw can I tell RubyGems that my gem is for 1.8 only?

---

<div class="post-metadata">

**Author:** ![Richard\_Conroy1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Richard\_Conroy1](https://rubytalk.org/u/Richard_Conroy1)\
**Post date:** [1 April 2010 03:27 UTC](https://rubytalk.org/t/a-question-about-gems/57917/4 "2010-04-01T03:27:04Z")

</div>

Hijacking this question a little, but how can I tell from my program what  
gems  
and what versions of those gems it is using?

If I knew what my programs gem dependencies were, I think it would really  
help  
me out on some very nasty issues. Last week for instance, it took me a  
couple  
of hours of trial and error to get my heroku .gems manifest to match the gem  
versions I was using in development.

> **···**
>
> On Thu, Apr 1, 2010 at 4:16 AM, Eric Hodel \<drbrain@segment7.net\> wrote:
> 
> > On Mar 28, 2010, at 16:21, Albert Schlef wrote:
> > 
> > \> I have a question about RubyGems's "~\>". Sorry for asking this here.  
> > \> I've searched in their "manual", but it's like searching a needle in a  
> > \> haystack.
> 
> --
> 
> > **[Richard Conroy's Personal Blog](http://richardconroy.blogspot.com)**
> >
> > Random thoughts on Life, Pictures, Sailing, Software Development, Games, Skiing and random things from the internet. May contain Rants.

---

<div class="post-metadata">

**Author:** ![Ryan\_Davis1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ryan_davis1/32/1848_2.png) [@Ryan\_Davis1](https://rubytalk.org/u/Ryan_Davis1)\
**Post date:** [1 April 2010 03:44 UTC](https://rubytalk.org/t/a-question-about-gems/57917/5 "2010-04-01T03:44:43Z")

</div>

YOU don't know what gems YOUR code is using? Why not?

One thing that might help is to try out the isolate gem. You specify what gems your project needs and they're privately installed and only those private gems get used. I use it on all my rails projects (and gem projects) at work.

> **···**
>
> On Mar 31, 2010, at 20:27 , Richard Conroy wrote:
> 
> > On Thu, Apr 1, 2010 at 4:16 AM, Eric Hodel \<drbrain@segment7.net\> wrote:
> > 
> > > On Mar 28, 2010, at 16:21, Albert Schlef wrote:
> > > 
> > > > I have a question about RubyGems's "~\>". Sorry for asking this here.  
> > > > I've searched in their "manual", but it's like searching a needle in a  
> > > > haystack.
> > 
> > Hijacking this question a little, but how can I tell from my program what  
> > gems  
> > and what versions of those gems it is using?
> > 
> > If I knew what my programs gem dependencies were, I think it would really  
> > help  
> > me out on some very nasty issues. Last week for instance, it took me a  
> > couple  
> > of hours of trial and error to get my heroku .gems manifest to match the gem  
> > versions I was using in development.

---

<div class="post-metadata">

**Author:** ![Richard\_Conroy1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Richard\_Conroy1](https://rubytalk.org/u/Richard_Conroy1)\
**Post date:** [1 April 2010 04:57 UTC](https://rubytalk.org/t/a-question-about-gems/57917/6 "2010-04-01T04:57:33Z")

</div>

> YOU don't know what gems YOUR code is using? Why not?

Is this meant to be easy to know? Sure I know when I explicitly use dust, or  
sinatra or  
Haml or whatever, but I can never be certain of the network of dependencies  
that those other  
gems use.

> One thing that might help is to try out the isolate gem. You specify what  
> gems your project needs and they're privately installed and only those  
> private gems get used. I use it on all my rails projects (and gem projects)  
> at work.

To be clear, I see this issue when checking out code across multiple systems  
which have  
different gems and gem versions installed. More specifically this is a  
thorny problem with  
non-explicit gem use, like when I choose to use a gem which in turn has  
other dependencies  
and incompatibility between different versions of the gems.

Had a bit of trial and error last week when I had to update my .gems  
manifest on Heroku to  
use a later version of datamapper and its dependencies. If I could have seen  
what gems &  
gem versions my development system was using it could have made for a much  
easier experience.

regards,  
Richard

> **···**
>
> On Thu, Apr 1, 2010 at 4:44 AM, Ryan Davis \<ryand-ruby@zenspider.com\> wrote:  
> --
> 
> > **[Richard Conroy's Personal Blog](http://richardconroy.blogspot.com)**
> >
> > Random thoughts on Life, Pictures, Sailing, Software Development, Games, Skiing and random things from the internet. May contain Rants.

---

<div class="post-metadata">

**Author:** ![Ryan\_Davis1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ryan_davis1/32/1848_2.png) [@Ryan\_Davis1](https://rubytalk.org/u/Ryan_Davis1)\
**Post date:** [1 April 2010 06:28 UTC](https://rubytalk.org/t/a-question-about-gems/57917/7 "2010-04-01T06:28:57Z")

</div>

> > YOU don't know what gems YOUR code is using? Why not?
> 
> Is this meant to be easy to know? Sure I know when I explicitly use dust, or  
> sinatra or  
> Haml or whatever, but I can never be certain of the network of dependencies  
> that those other  
> gems use.

Ah. well... rubygems handles the transitive closure of the dependencies. You should only specify the top level (real) dependencies for your project.

> > One thing that might help is to try out the isolate gem. You specify what  
> > gems your project needs and they're privately installed and only those  
> > private gems get used. I use it on all my rails projects (and gem projects)  
> > at work.

> To be clear, I see this issue when checking out code across multiple systems  
> which have  
> different gems and gem versions installed. More specifically this is a  
> thorny problem with  
> non-explicit gem use, like when I choose to use a gem which in turn has  
> other dependencies  
> and incompatibility between different versions of the gems.

This is exactly the type of thing that isolate solves. It is perfectly reasonable to have isolate installed as the only global gem and each project uses isolate to declare their gem dependencies and they're all installed private to each project.

> **···**
>
> On Mar 31, 2010, at 21:57 , Richard Conroy wrote:
> 
> > On Thu, Apr 1, 2010 at 4:44 AM, Ryan Davis \<ryand-ruby@zenspider.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Richard\_Conroy1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Richard\_Conroy1](https://rubytalk.org/u/Richard_Conroy1)\
**Post date:** [1 April 2010 07:21 UTC](https://rubytalk.org/t/a-question-about-gems/57917/8 "2010-04-01T07:21:32Z")

</div>

I will look into isolate, though the problem I face isn't due to  
production/professional environments.

I often evaluate different gems or run through example code as part of  
course work or general curiosity.  
Sometimes I settle on a solution that I take further on, and its usually at  
that stage that I need to figure  
out exact gem dependencies. I often end up being shanghaied into helping out  
someone else's ruby  
problem as well. The messiest issues are always gem related.

I was just curious if there was a mechanism to inspect the loaded gems from  
an application (and their  
versions). Even unusual techniques, like perhaps objectspace inspection, or  
reopening gem specific  
methods.

Just curious if anyone knew any techniques.

> **···**
>
> On Thu, Apr 1, 2010 at 7:28 AM, Ryan Davis \<ryand-ruby@zenspider.com\> wrote:
> 
> > On Mar 31, 2010, at 21:57 , Richard Conroy wrote:  
> > \> To be clear, I see this issue when checking out code across multiple  
> > systems  
> > \> which have  
> > \> different gems and gem versions installed. More specifically this is a  
> > \> thorny problem with  
> > \> non-explicit gem use, like when I choose to use a gem which in turn has  
> > \> other dependencies  
> > \> and incompatibility between different versions of the gems.
> > 
> > This is exactly the type of thing that isolate solves. It is perfectly  
> > reasonable to have isolate installed as the only global gem and each project  
> > uses isolate to declare their gem dependencies and they're all installed  
> > private to each project.
> 
> --
> 
> > **[Richard Conroy's Personal Blog](http://richardconroy.blogspot.com)**
> >
> > Random thoughts on Life, Pictures, Sailing, Software Development, Games, Skiing and random things from the internet. May contain Rants.

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [1 April 2010 08:17 UTC](https://rubytalk.org/t/a-question-about-gems/57917/9 "2010-04-01T08:17:16Z")

</div>

ri Gem.loaded\_specs

> **···**
>
> On Apr 1, 2010, at 00:21, Richard Conroy wrote:
> 
> > I often evaluate different gems or run through example code as part of  
> > course work or general curiosity.  
> > Sometimes I settle on a solution that I take further on, and its usually at  
> > that stage that I need to figure  
> > out exact gem dependencies. I often end up being shanghaied into helping out  
> > someone else's ruby  
> > problem as well. The messiest issues are always gem related.
> > 
> > I was just curious if there was a mechanism to inspect the loaded gems from  
> > an application (and their  
> > versions). Even unusual techniques, like perhaps objectspace inspection, or  
> > reopening gem specific  
> > methods.

---

<div class="post-metadata">

**Author:** ![Richard\_Conroy1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Richard\_Conroy1](https://rubytalk.org/u/Richard_Conroy1)\
**Post date:** [1 April 2010 08:46 UTC](https://rubytalk.org/t/a-question-about-gems/57917/10 "2010-04-01T08:46:53Z")

</div>

Thanks! Exactly what I wanted!

> **···**
>
> On Thu, Apr 1, 2010 at 9:17 AM, Eric Hodel \<drbrain@segment7.net\> wrote:
> 
> > ri Gem.loaded\_specs
> 
> --
> 
> > **[Richard Conroy's Personal Blog](http://richardconroy.blogspot.com)**
> >
> > Random thoughts on Life, Pictures, Sailing, Software Development, Games, Skiing and random things from the internet. May contain Rants.
