Wxruby and rubygems seems not to work?

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

kazaam wrote:

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

On Aug 22, 2007, at 09:20, kazaam wrote:

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.

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?!?

kazaam schrieb:

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

thx with:
require ‘rubygems’
require ‘wx’

include Wx

it works fine :slight_smile:

kazaam wrote:

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