wxruby and rubygems seems not to work?

K

kazaam

Like here: http://wxruby.rubyforge.org/wiki/wiki.pl?Installation suggested I installed wxruby2 on my linux machine with:
sudo gem install wxruby2-preview
Then I tried this sample: http://wxruby.rubyforge.org/wiki/wiki.pl?Getting_Started , I modified it to run for me:

#!/usr/bin/env ruby

$Verbose=true

require 'rubygems'
gem 'wxruby2-preview'


class MinimalApp < App
def on_init
Frame.new(nil, -1, "The Bare Minimum").show()
end
end


MinimalApp.new.main_loop

but always when I execute it I'm getting this error:
laptop:~/Desktop$ ./gui.rb
../gui.rb:9: uninitialized constant App (NameError)
laptop:~/Desktop$

My machine is an Ubuntu feisty fawn and
gem: 0.9.0
ruby: 1.8.5 (2006-08-25) [i486-linux]
wxruby2-preview: 0.0.40 .

What did I wrong?!? Can someone point me to my mistake? Is there a difference between wxruby2-preview and wxruby2? But there is no wxruby2 gem just this -preview one?

bye
 
K

kazaam

okay I'm a bit further. I found out that this here:

#!/usr/bin/env ruby

$Verbose=true

require 'wx'
include Wx

class MinimalApp < App
def on_init
Frame.new(nil, -1, "The Bare Minimum").show()
end
end


MinimalApp.new.main_loop

Works perfectly if I start it with "ruby -rubygems gui.rb" but I can't get it to run if I wanna start it simple with ./gui.rb ?!? Also if I include:
require 'rubygems'
it refuses to work... that's really weired?!?
 
A

Alex Fenton

kazaam said:
require 'rubygems'
gem 'wxruby2-preview'


class MinimalApp < App

the error is here.
./gui.rb:9: uninitialized constant App (NameError)
laptop:~/Desktop$

You have chopped out a bit too much from the sample you copied. The
class you want to inherit from is Wx::App, so you need to either
reference it fully:

class MinimalApp < Wx::App

or, include the whole Wx module in your main namespace at the beginning
of your script (as in the sample you started from):

include Wx

Then you don't have to add the Wx:: prefix whenever you reference a
wxRuby class or other constant. The choice is yours; "include" saves a
bit of typing in short scripts, but it's probably clearer to use the
Wx:: prefix in bigger applications.
ruby: 1.8.5 (2006-08-25) [i486-linux]
wxruby2-preview: 0.0.40 .

Not relevant to your error, but I'd recommend upgrading to wxruby-1.9.0,
which is a newer, beta-quality release off the wxruby2-preview series.

alex
 
S

Stefan Mahlitz

kazaam said:
Like here: http://wxruby.rubyforge.org/wiki/wiki.pl?Installation suggested I installed wxruby2 on my linux machine with:
sudo gem install wxruby2-preview
Then I tried this sample: http://wxruby.rubyforge.org/wiki/wiki.pl?Getting_Started , I modified it to run for me:

#!/usr/bin/env ruby

$Verbose=true

require 'rubygems'
gem 'wxruby2-preview'


class MinimalApp < App
def on_init
Frame.new(nil, -1, "The Bare Minimum").show()
end
end


MinimalApp.new.main_loop

but always when I execute it I'm getting this error:
laptop:~/Desktop$ ./gui.rb
./gui.rb:9: uninitialized constant App (NameError)
laptop:~/Desktop$

You missed two lines of the tutorial:

require "wx" # wxruby2
include Wx

they should be placed below your require "rubygems"

If you leave out 'include Wx' you will have to write Wx::App, Wx::Frame etc.

Stefan
 
E

Eric Hodel

Like here: http://wxruby.rubyforge.org/wiki/wiki.pl?Installation
suggested I installed wxruby2 on my linux machine with:
sudo gem install wxruby2-preview
Then I tried this sample: http://wxruby.rubyforge.org/wiki/wiki.pl?
Getting_Started , I modified it to run for me:

#!/usr/bin/env ruby

$Verbose=true

require 'rubygems'
gem 'wxruby2-preview'


class MinimalApp < App

gem doesn't require any files, you need to call require for that.

The only time you need to call gem is when you want a specific
version of a gem.

No matter what, you must call require.
 
S

Stefan Mahlitz

kazaam said:
okay I'm a bit further. I found out that this here:

#!/usr/bin/env ruby

$Verbose=true

require 'wx'
include Wx

class MinimalApp < App
def on_init
Frame.new(nil, -1, "The Bare Minimum").show()
end
end


MinimalApp.new.main_loop

Works perfectly if I start it with "ruby -rubygems gui.rb" but I can't get it to run if I wanna start it simple with ./gui.rb ?!? Also if I include:
require 'rubygems'
it refuses to work... that's really weired?!?

Can you show the error message? If it is "permission denied" you'd have
to change the file permission to executable.

Make sure that you include a shebang line in your gui.rb

Running ruby -rrubygems should be equal to having 'require "rubygems"'
in your file.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top