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?

···

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

Max Russell 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".

···

--
Paul Lutus
http://www.arachnoid.com

Max Russell wrote:

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

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

Then you're are trying to 'require' your own script.

-Thomas

···

On 23/09/06, Max Russell <thedossone@gmail.com> wrote:

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?

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

your script is named 'blinkenlights.rb', right?

--
www.LuLaLiebe.de - Kennenlernen, Treffen, Verlieben
...finde deinen Traumparter bei LuLaLiebe!

Paul Lutus wrote:

Max Russell 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)

···

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

Thomas P. wrote:

···

On 23/09/06, Max Russell <thedossone@gmail.com> 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....

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

Max Russell 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.

···

--
Paul Lutus
http://www.arachnoid.com

Max Russell 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

Paul Lutus wrote:

Max Russell 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.

···

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

Jordan Callicoat wrote:

Max Russell 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?

···

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

Max Russell wrote:

Paul Lutus wrote:

Max Russell 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?

···

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

Max Russell 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 Vallner

Max Russell wrote:

Ruby 1.8.4
Gem 0.9.0
Blinkenlights 0.0.4

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?

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

Dave Burt wrote:

Max Russell 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...

···

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