[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Cookbook example - uninitialized constant

Max Russell

9/23/2006 2:19:00 PM

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

12 Answers

Paul Lutus

9/23/2006 3:42:00 PM

0

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

Dave Burt

9/25/2006 12:31:00 AM

0

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

Max Russell

9/25/2006 7:50:00 AM

0

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

Paul Lutus

9/25/2006 3:25:00 PM

0

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

Max Russell

9/26/2006 7:18:00 PM

0

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

Max Russell

9/26/2006 8:21:00 PM

0

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

Dave Burt

9/26/2006 9:44:00 PM

0

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

Max Russell

9/28/2006 11:34:00 AM

0

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

Max Russell

9/29/2006 8:16:00 AM

0

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

MonkeeSage

9/29/2006 8:41:00 AM

0

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