Forum: Ruby How to get installed module version

Posted by Abhishek K. (abhishek_k)
on 2012-10-04 11:49
Hi,

I am new to ruby, just need one liner command in ruby to check any
installed version. like in perl we do

perl -MABC -e 'print "$ABC::VERSION"'
Posted by "Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> (Guest)
on 2012-10-04 11:56
(Received via mailing list)
On Thu, Oct 4, 2012 at 11:49 AM, Abhishek K. <lists@ruby-forum.com> 
wrote:
> Hi,
>
> I am new to ruby, just need one liner command in ruby to check any
> installed version. like in perl we do
>
> perl -MABC -e 'print "$ABC::VERSION"'

$ gem list nokogiri

*** LOCAL GEMS ***

nokogiri (1.5.5, 1.5.0)

Jesus.
Posted by Abhishek K. (abhishek_k)
on 2012-10-04 12:03
"Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> wrote in post 
#1078598:
> On Thu, Oct 4, 2012 at 11:49 AM, Abhishek K. <lists@ruby-forum.com>
> wrote:
>> Hi,
>>
>> I am new to ruby, just need one liner command in ruby to check any
>> installed version. like in perl we do
>>
>> perl -MABC -e 'print "$ABC::VERSION"'
>
> $ gem list nokogiri
>
> *** LOCAL GEMS ***
>
> nokogiri (1.5.5, 1.5.0)
>
> Jesus.

Thanks Jesus, is there any way i can get by ruby command like

ruby1.8 -rMODULE -e 'puts ....'
ruby1.9.1 -rMODULE -e 'puts ....'
Posted by Lars Haugseth (Guest)
on 2012-10-04 12:23
(Received via mailing list)
On 10/04/2012 12:03 PM, Abhishek K. wrote:
>>
>> nokogiri (1.5.5, 1.5.0)
>
> Thanks Jesus, is there any way i can get by ruby command like
>
> ruby1.8 -rMODULE -e 'puts ....'
> ruby1.9.1 -rMODULE -e 'puts ....'

If you want to search for more information on this topic, note that the
correct term for "modules" in the Ruby world is "gems".

You can get at information about installed gems from Ruby code through
the Gem::Specification class.

   http://rubygems.rubyforge.org/rubygems-update/Gem/...

What are you going to do with that information, though? If your code
depends on certain versions of gems, you should take a look at Bundler.

   http://gembundler.com/
Posted by Abhishek K. (abhishek_k)
on 2012-10-04 12:32
Lars Haugseth wrote in post #1078607:
> On 10/04/2012 12:03 PM, Abhishek K. wrote:
>>>
>>> nokogiri (1.5.5, 1.5.0)
>>
>> Thanks Jesus, is there any way i can get by ruby command like
>>
>> ruby1.8 -rMODULE -e 'puts ....'
>> ruby1.9.1 -rMODULE -e 'puts ....'
>
> If you want to search for more information on this topic, note that the
> correct term for "modules" in the Ruby world is "gems".
>
> You can get at information about installed gems from Ruby code through
> the Gem::Specification class.
>
>    http://rubygems.rubyforge.org/rubygems-update/Gem/...
>
> What are you going to do with that information, though? If your code
> depends on certain versions of gems, you should take a look at Bundler.
>
>    http://gembundler.com/
thanks for your responce

I need to check what all gems(modules) installed and what is therir 
version on each version of ruby, we have two version installed ruby1.8 
and ruby1.92

i am looking something we do in perl and python same way in ruby like

perl -MABC -e 'print "$ABC::VERSION"'

python -c "import MODULE; print (MODULE.__version__)";
Posted by Lars Haugseth (Guest)
on 2012-10-04 14:03
(Received via mailing list)
On 10/04/2012 12:32 PM, Abhishek K. wrote:
> i am looking something we do in perl and python same way in ruby like
>
> perl -MABC -e 'print "$ABC::VERSION"'
>
> python -c "import MODULE; print (MODULE.__version__)";

List all gems and their version:

$ ruby -e 'puts Gem::Specification.map {|gem| "#{gem.name}:
#{gem.version}"}'

List all installed versions of a particular gem:

$ ruby -e 'puts 
Gem::Specification.find_all_by_name("rake").map(&:version)'
Posted by Abhishek K. (abhishek_k)
on 2012-10-05 06:58
Lars Haugseth wrote in post #1078619:
> On 10/04/2012 12:32 PM, Abhishek K. wrote:
>> i am looking something we do in perl and python same way in ruby like
>>
>> perl -MABC -e 'print "$ABC::VERSION"'
>>
>> python -c "import MODULE; print (MODULE.__version__)";
>
> List all gems and their version:
>
> $ ruby -e 'puts Gem::Specification.map {|gem| "#{gem.name}:
> #{gem.version}"}'
>
> List all installed versions of a particular gem:
>
> $ ruby -e 'puts
> Gem::Specification.find_all_by_name("rake").map(&:version)'

Thanks Lars.

This is not giving all but only inside Gems dir
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.