[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

RUBYOPT="rubygems" doesn't feel good...

Erik Veenstra

3/28/2005 7:50:00 AM

When you set RUBYOPT to "rubygems", library ubygems is
automatically required before starting the application. You
don't have to do a require of (r)ubygems in the application
itself anymore. If the application doesn't require rubygems
internally, it can only run in an environment in which RUBYOPT
is set to "rubygems".

What happens when such an application is shipped to a machine
which does have rubygems and the right gems, (so it should be
able to run perfectly), but doesn't have RUBYOPT set to require
rubygems? The only solution to get such an application to work
(out of the box) is to set RUBYOPT as well, which does affect
the other applications...

It just doesn't feel good...

gegroet,
Erik V.

5 Answers

Christian Neukirchen

3/28/2005 1:43:00 PM

0

"Erik Veenstra" <google@erikveen.dds.nl> writes:

> When you set RUBYOPT to "rubygems", library ubygems is
> automatically required before starting the application. You
> don't have to do a require of (r)ubygems in the application
> itself anymore. If the application doesn't require rubygems
> internally, it can only run in an environment in which RUBYOPT
> is set to "rubygems".
>
> What happens when such an application is shipped to a machine
> which does have rubygems and the right gems, (so it should be
> able to run perfectly), but doesn't have RUBYOPT set to require
> rubygems? The only solution to get such an application to work
> (out of the box) is to set RUBYOPT as well, which does affect
> the other applications...
>
> It just doesn't feel good...

Still better than forcing the other users to have gems installed...
IMO, the best thing is

begin
require 'rubygems'
rescue LoadError
end

> gegroet,
> Erik V.
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...


Erik Veenstra

3/28/2005 2:17:00 PM

0

> IMO, the best thing is
>
> begin
> require 'rubygems'
> rescue LoadError
> end

Why? I bet you foresee something I missed.

gegroet,
Erik V.

Christian Neukirchen

3/28/2005 4:38:00 PM

0

"Erik Veenstra" <google@erikveen.dds.nl> writes:

>> IMO, the best thing is
>>
>> begin
>> require 'rubygems'
>> rescue LoadError
>> end
>
> Why? I bet you foresee something I missed.

You don't need to have gems installed; you can simply install the
libraries (assuming they have the same name as the gems). And, you
don't need to have RUBYOPTS set.

I don't think there is an easier way.

> gegroet,
> Erik V.
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...


Erik Veenstra

3/28/2005 5:13:00 PM

0

> You don't need to have gems installed; you can simply install
> the libraries (assuming they have the same name as the gems).
> And, you don't need to have RUBYOPTS set.

Oh, I see what you mean... But it's not what I'm talking about.
That's why I was a bit confused.

I, the customer have installed RubyGems, as well as the gems on
which the application depends, but I didn't set RUBYOPT. When
you, the developer, give me an application which doesn't
require rubygems internally, it's not going to run on my
machine. Is it? You could easily avoid that by doing a "require
'rubygems'" internally. There's no need to rescue it.

You're talking about whether I, the customer, need to install
RubyGems at all. You could avoid that "have to" by rescuing the
"require 'rubygems'". Well, in theory, but no in practice. See
the examples.

"In theory there is no difference between theory and practice.
In practice there is."...

gegroet,
Erik V.

----------------------------------------------------------------

# Example 1

require "rubygems"
require "sqlite"

----------------------------------------------------------------

# Example 2

$: << "/usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/"
require "sqlite"

----------------------------------------------------------------

Christian Neukirchen

3/28/2005 7:52:00 PM

0

"Erik Veenstra" <google@erikveen.dds.nl> writes:

>> You don't need to have gems installed; you can simply install
>> the libraries (assuming they have the same name as the gems).
>> And, you don't need to have RUBYOPTS set.
>
> Oh, I see what you mean... But it's not what I'm talking about.
> That's why I was a bit confused.
>
> I, the customer have installed RubyGems, as well as the gems on
> which the application depends, but I didn't set RUBYOPT. When
> you, the developer, give me an application which doesn't
> require rubygems internally, it's not going to run on my
> machine. Is it? You could easily avoid that by doing a "require
> 'rubygems'" internally. There's no need to rescue it.

The issue is that I for myself, the developer do not use rubygems.
But your statement is correct: If you want to use software that
doesn't require 'rubygems' for reasons whatsoever, you'll need to set
RUBYOPT or run the program with -rubygems.

> You're talking about whether I, the customer, need to install
> RubyGems at all. You could avoid that "have to" by rescuing the
> "require 'rubygems'". Well, in theory, but no in practice. See
> the examples.

This works in practice too.

> "In theory there is no difference between theory and practice.
> In practice there is."...
>
> gegroet,
> Erik V.
>
> # Example 1
> require "rubygems"
> require "sqlite"
>
> # Example 2
> $: << "/usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/"
> require "sqlite"

On *my* box, Example 2 will run, as sqlite is likely to be installed
elsewhere. Do not ever do that, though. If you want to use a gem on
your box, use a captured require 'rubygems'.

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...