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