[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Fox vs Fox12

pkchau

3/27/2005 5:33:00 AM

I'm writing a very simple FxRuby application. When I run it on a newer
version of FxRuby I need to require 'fox12'. When I run it on an older
version, it needs require 'fox'. It seems to work fine on both
environments except that that I need to change the require. I want to
make the application generic so that it runs on both environments by
doing something like:


if require 'fox'
require 'fox'
require 'fox/colors'
include Fox
elsif require 'fox12'
require 'fox12'
require 'fox12/colors'
include Fox
else
# do something different
exit
end


However, this doesn't work -> LoadError: No such file to load -- fox.
How can I overcome this problem.
6 Answers

Hal E. Fulton

3/27/2005 6:13:00 AM

0

Peter C wrote:
>

[snip]

> However, this doesn't work -> LoadError: No such file to load -- fox.
> How can I overcome this problem.

require returns true if successful and false if already loaded.
If a file is not found, it raises an exception.

Something like this?

begin
require 'fox'
require 'fox/colors'
rescue
begin
require 'fox12'
require 'fox12/colors'
rescue
puts "Oops..."
end
end

include Fox

I don't recall nesting begin/end that way before,
but it should work... someone see a better way?


Hal




martinus

3/28/2005 3:35:00 PM

0

> I'm writing a very simple FxRuby application. When I run it on a newer
> version of FxRuby I need to require 'fox12'. When I run it on an older
> version, it needs require 'fox'. It seems to work fine on both
> environments except that that I need to change the require. I want to
> make the application generic so that it runs on both environments by
> doing something like:

I use the following code in XDCC-Fetch. It works with Fox 1.0, Fox 1.2,
and Fox installed via rubygems. In Fox 1.0 several classes have
different names than in 1.2, so I create aliases. Sometimes the
arguments of method calls are also different, for this I set the
FOXVERSION which I use to switch between different code.



# Load FXRuby: try gem, then Fox 1.2, then Fox 1.0
begin
# try fxruby gem
require 'rubygems'
require_gem 'fxruby', '>= 1.1.0'
require 'fox12'
require 'fox12/colors'
FOXVERSION="1.2"
include Fox
rescue LoadError
# no gem? try fox12 direct.
begin
require "fox12"
require "fox12/colors"
FOXVERSION="1.2"
include Fox
rescue LoadError
# no gem, no fox12? try fox 1.0
require "fox"
require "fox/colors"
# grep for FOXVERSION to find all code that depends on this
FOXVERSION="1.0"
include Fox
FXMenuBar = FXMenubar
FXToolTip = FXTooltip
FXStatusBar = FXStatusbar
end
end

Kero van Gelder

3/28/2005 4:45:00 PM

0

>> I'm writing a very simple FxRuby application. When I run it on a newer
>> version of FxRuby I need to require 'fox12'. When I run it on an older
>> version, it needs require 'fox'. It seems to work fine on both
>> environments except that that I need to change the require. I want to
>> make the application generic so that it runs on both environments by
>> doing something like:
>
> I use the following code in XDCC-Fetch. It works with Fox 1.0, Fox 1.2,
> and Fox installed via rubygems. In Fox 1.0 several classes have
> different names than in 1.2, so I create aliases. Sometimes the
> arguments of method calls are also different, for this I set the
> FOXVERSION which I use to switch between different code.

Can somebody PLEASE improve on the code below?
I mean... "require 'fox'" should just do it.
I know RUBY_OPTIONS can help with gems, but this fox vs fox12 stinks, too.
.... and this FOXVERSION and aliasing stuff... man, horrible.

Note I use neither gems nor fox, but if this is 'normal' to get it
working, I ain't gonna use them!!

(at least put the line "include Fox" below the rest, only once instead of
three times...)

> # Load FXRuby: try gem, then Fox 1.2, then Fox 1.0
> begin
> # try fxruby gem
> require 'rubygems'
> require_gem 'fxruby', '>= 1.1.0'
> require 'fox12'
> require 'fox12/colors'
> FOXVERSION="1.2"
> include Fox
> rescue LoadError
> # no gem? try fox12 direct.
> begin
> require "fox12"
> require "fox12/colors"
> FOXVERSION="1.2"
> include Fox
> rescue LoadError
> # no gem, no fox12? try fox 1.0
> require "fox"
> require "fox/colors"
> # grep for FOXVERSION to find all code that depends on this
> FOXVERSION="1.0"
> include Fox
> FXMenuBar = FXMenubar
> FXToolTip = FXTooltip
> FXStatusBar = FXStatusbar
> end
> end

+--- Kero ----------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://httpd.chello.nl/k... ---+

martinus

3/28/2005 5:17:00 PM

0

You cannot put "include Fox" below the rest, because then the aliases
would not work. But I am pretty sure you can write it in a cleaner way,
for me this quick hack was good enough :)

martinus

Lyle Johnson

3/28/2005 9:44:00 PM

0

On Tue, 29 Mar 2005 01:49:46 +0900, Kero <kero@chello.single-dot.nl> wrote:

> Can somebody PLEASE improve on the code below?
> I mean... "require 'fox'" should just do it.
> I know RUBY_OPTIONS can help with gems, but this fox vs fox12 stinks, too.
> .... and this FOXVERSION and aliasing stuff... man, horrible.

Just to make something clear here: There were a number of API changes
between FOX versions 1.0 and 1.2, and thus FOX version 1.2 isn't
completely backwards-compatible with FOX 1.0.

It sounds like the original poster (Peter) in is the fortunate
situation that his code happens to run just fine under either FOX
version, but that's definitely the exception and not the rule. IMO, it
would be preferable for application developers to go ahead and update
their application(s) to FOX 1.2.


Richard Lyman

3/28/2005 10:02:00 PM

0

On Tue, 29 Mar 2005 06:43:33 +0900, Lyle Johnson <lyle.johnson@gmail.com> wrote:
> On Tue, 29 Mar 2005 01:49:46 +0900, Kero <kero@chello.single-dot.nl> wrote:
>
> > Can somebody PLEASE improve on the code below?
> > I mean... "require 'fox'" should just do it.
> > I know RUBY_OPTIONS can help with gems, but this fox vs fox12 stinks, too.
> > .... and this FOXVERSION and aliasing stuff... man, horrible.
>
> Just to make something clear here: There were a number of API changes
> between FOX versions 1.0 and 1.2, and thus FOX version 1.2 isn't
> completely backwards-compatible with FOX 1.0.
>
> It sounds like the original poster (Peter) in is the fortunate
> situation that his code happens to run just fine under either FOX
> version, but that's definitely the exception and not the rule. IMO, it
> would be preferable for application developers to go ahead and update
> their application(s) to FOX 1.2.
>
>


I'm kinda shocked that it runs under both versions. I mean - FOX 1.0
used 'Menubar' and FOX 1.2 introduced better consistency in the API
with 'MenuBar'. If your application uses a menu bar for it's menus
then you'd have to write something to switch the spelling...

-Rich