# Wxruby and rubygems seems not to work?

**URL:** <https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737>\
**Category:** Ruby\
**Created:** [August 22, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737 "2007-08-22T18:20:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 22, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737/1 "2007-08-22T18:20:51Z")

</div>

Like here: [http://wxruby.rubyforge.org/wiki/wiki.pl?Installation](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](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

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 22, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737/2 "2007-08-22T20:51:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 22, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737/3 "2007-08-22T20:52:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 22, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737/4 "2007-08-22T23:02:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 22, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737/5 "2007-08-22T23:17:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [September 25, 2007, 11:04pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737/6 "2007-09-25T23:04:18Z")

</div>

thx with:  
require ‘rubygems’  
require ‘wx’

include Wx

it works fine 🙂

---

<div class="post-metadata">

**Author:** ![kazaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b4bc9f/32.png) [@kazaam](https://www.ruby-forum.com/u/kazaam)\
**Post date:** [August 22, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/wxruby-and-rubygems-seems-not-to-work/112737/7 "2007-08-22T22:44:10Z")

</div>

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
