Cookbook example - uninitialized constant

Cross posting this from Ubuntu forums

I recently got the excellent Ruby cookbook and scanning through quickly
seized upon the Blinkenlights examples.

However I’m seeing something like this:
./blinkenlights.rb
./blinkenlights.rb:7: uninitialized constant BlinkenLights (NameError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
from ./blinkenlights.rb:4

whenever I try to execute the script
#!/usr/bin/ruby

require ‘rubygems’
require ‘blinkenlights’

#Turn individual lights on and off
BlinkenLights.open do |lights|
lights.left = true
lights.middle = true
lights.right = true

lights.scr = false
lights.cap = false
lights.num = false
end

#Dislay a light show
BlinkenLights.open do |lights|
lights.left_to_right
10.times{ lights.random }
lights.right_to_left
end

I’m on Ubuntu 6.06 LTS and I have the Blinkenlightsgem installed, I used
sudo gem install blinkenlights and can list my local gems and see it.

So why do I get this error?

Max R. wrote:

/ …

I’m on Ubuntu 6.06 LTS and I have the Blinkenlightsgem installed, I used
sudo gem install blinkenlights and can list my local gems and see it.

So why do I get this error?

My guess is the class is named “Blinkenlights”, not “BlinkenLights”.

Max R. wrote:

from ./blinkenlights.rb:4

I’m on Ubuntu 6.06 LTS and I have the Blinkenlightsgem installed, I used
sudo gem install blinkenlights and can list my local gems and see it.

So why do I get this error?

I’m a bit mystified and don’t have a Ubuntu box, but I’ll ask some
clarifying questions anyway. What versions of Ruby, Rubygems and
BlinkenLights are you running?

ruby --version
gem --version
gem list | grep blinken

Cheers,
Dave

Paul L. wrote:

Max R. wrote:

/ …

I’m on Ubuntu 6.06 LTS and I have the Blinkenlightsgem installed, I used
sudo gem install blinkenlights and can list my local gems and see it.

So why do I get this error?

My guess is the class is named “Blinkenlights”, not “BlinkenLights”.

I’ve checked this out in the blinkenlights documentation.

Interestingly I’ve tried this usign IRB on a Windows machine and can run
the functionality, however if I try the same script executed from file,
I get the uninitialized constant error.

I’ll check my versions at home, but believe it to be Ruby 1.8 with
latest gem and blinkelights (installed them 2 days ago)

Paul L. wrote:

Max R. wrote:

Interestingly I’ve tried this usign IRB on a Windows machine and can run
the functionality, however if I try the same script executed from file,
I get the uninitialized constant error.

Possibly there are two or more different versions of Ruby on your
machine,
and each is activated in different circumstances. Or the IRB invocation
differs in some subtle way from that in the source file.

I’ve just checked this out:

Ruby 1.8.4
Gem 0.9.0
Blinkenlights 0.0.4

I’ve made sure that my system is consistent with only 1.8.x versions of
Ruby and libraries, so this one confuses me.

Max R. wrote:

Interestingly I’ve tried this usign IRB on a Windows machine and can run
the functionality, however if I try the same script executed from file,
I get the uninitialized constant error.

Possibly there are two or more different versions of Ruby on your
machine,
and each is activated in different circumstances. Or the IRB invocation
differs in some subtle way from that in the source file.

Dave B. wrote:

Max R. wrote:

Ruby 1.8.4
Gem 0.9.0
Blinkenlights 0.0.4

irb(main):001:0> require ‘blinkenlights’
LoadError: no such file to load – blinkenlights
from (irb):1:in `require’
from (irb):1

So why would gem report that the gem is there, but IRB not think it
installed?

You’ll need to require ‘rubygems’ first. (The Windows One-Click
Installer sets the environment variable RUBYOPT=rubygems so that
rubygems is automatically required when Ruby is run.)

FWIW, I’m using the same versions as you on my Windows box, and the
script works for me.

Cheers,
Dave

Thanks- my home box is Ubuntu though and that is principally where I
want to run this…

Max R. wrote:

Paul L. wrote:

Max R. wrote:

Interestingly I’ve tried this usign IRB on a Windows machine and can run
the functionality, however if I try the same script executed from file,
I get the uninitialized constant error.

Possibly there are two or more different versions of Ruby on your
machine,
and each is activated in different circumstances. Or the IRB invocation
differs in some subtle way from that in the source file.

I’ve just checked this out:

Ruby 1.8.4
Gem 0.9.0
Blinkenlights 0.0.4

I’ve made sure that my system is consistent with only 1.8.x versions of
Ruby and libraries, so this one confuses me.

Aha! More interesting stuff-

trying this out again on my Ubuntu box

it echos out the version if I do gem list | grep blinken
and if I list my local gems, I can see it in there,

however

going in through IRB and trying what I could do with the Windows box I
find:

irb(main):001:0> require ‘blinkenlights’
LoadError: no such file to load – blinkenlights
from (irb):1:in `require’
from (irb):1

So why would gem report that the gem is there, but IRB not think it
installed?

Max R. wrote:

Ruby 1.8.4
Gem 0.9.0
Blinkenlights 0.0.4

irb(main):001:0> require ‘blinkenlights’
LoadError: no such file to load – blinkenlights
from (irb):1:in `require’
from (irb):1

So why would gem report that the gem is there, but IRB not think it
installed?

You’ll need to require ‘rubygems’ first. (The Windows One-Click
Installer sets the environment variable RUBYOPT=rubygems so that
rubygems is automatically required when Ruby is run.)

FWIW, I’m using the same versions as you on my Windows box, and the
script works for me.

Cheers,
Dave

On 23/09/06, Max R. [email protected] wrote:

`require’
BlinkenLights.open do |lights|
BlinkenLights.open do |lights|
So why do I get this error?


Posted via http://www.ruby-forum.com/.

your script is named ‘blinkenlights.rb’, right?

Then you’re are trying to ‘require’ your own script.

-Thomas

Thomas P. wrote:

On 23/09/06, Max R. [email protected] wrote:

`require’
BlinkenLights.open do |lights|
BlinkenLights.open do |lights|
So why do I get this error?


Posted via http://www.ruby-forum.com/.

your script is named ‘blinkenlights.rb’, right?

Then you’re are trying to ‘require’ your own script.

-Thomas

Tried renaming it also, with no success. It still compains that
BlinkenLights is and unitialised constant. This seems strange as I’ve
read through the source for the gem and the test examples, as well as
the rubyforge documentation and this does appear to be the method of
calling it…

Max R. wrote:

Tried renaming it also, with no success. It still compains that
BlinkenLights is and unitialised constant. This seems strange as I’ve
read through the source for the gem and the test examples, as well as
the rubyforge documentation and this does appear to be the method of
calling it…

Try:

RUBYOPT=-rauto_gem ruby yourfile.rb

Regards,
Jordan

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Max R. wrote:

Try:

RUBYOPT=-rauto_gem ruby yourfile.rb

Regards,
Jordan

Thanks- is this a system wide environment variable or should I just add
this to the top of the script?

Nope, that’s a shell command - changes the environment for that one
invocation of ruby.

David V.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFHb00y6MhrS8astoRAmjPAJwJTeKrbFzm+se0/ZunLaE77D7o+ACfcUi/
r3etiv0bvHJkbgZZq96P+Pw=
=3fB1
-----END PGP SIGNATURE-----

Jordan Callicoat wrote:

Max R. wrote:

Tried renaming it also, with no success. It still compains that
BlinkenLights is and unitialised constant. This seems strange as I’ve
read through the source for the gem and the test examples, as well as
the rubyforge documentation and this does appear to be the method of
calling it…

Try:

RUBYOPT=-rauto_gem ruby yourfile.rb

Regards,
Jordan

Thanks- is this a system wide environment variable or should I just add
this to the top of the script?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs