[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

new instance (uninitialized constant

Thufir Hawat

11/3/2007 4:24:00 AM

I need to indicate where to find the Song class. With a module? I'm
looking for the simplest technique (hint pls):

C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>type Song.rb
class Song
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
end
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>type Sing.rb
aSong = Song.new("Bicylops", "Fleck", 260)
C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>Sing.rb
C:/Documents and Settings/nsaunders/Desktop/Sing.rb:1: uninitialized
constant So
ng (NameError)

C:\Documents and Settings\nsaunders\Desktop>
C:\Documents and Settings\nsaunders\Desktop>



thanks,

Thufir


3 Answers

Morton Goldberg

11/3/2007 6:47:00 AM

0

On Nov 3, 2007, at 12:24 AM, Thufir wrote:

> I need to indicate where to find the Song class. With a module? I'm
> looking for the simplest technique (hint pls):
>
> C:\Documents and Settings\nsaunders\Desktop>
> C:\Documents and Settings\nsaunders\Desktop>
> C:\Documents and Settings\nsaunders\Desktop>type Song.rb
> class Song
> def initialize(name, artist, duration)
> @name = name
> @artist = artist
> @duration = duration
> end
> end
> C:\Documents and Settings\nsaunders\Desktop>
> C:\Documents and Settings\nsaunders\Desktop>type Sing.rb
> aSong = Song.new("Bicylops", "Fleck", 260)
> C:\Documents and Settings\nsaunders\Desktop>
> C:\Documents and Settings\nsaunders\Desktop>Sing.rb
> C:/Documents and Settings/nsaunders/Desktop/Sing.rb:1: uninitialized
> constant So
> ng (NameError)
>
> C:\Documents and Settings\nsaunders\Desktop>
> C:\Documents and Settings\nsaunders\Desktop>

Hint: Insert

require 'Song'

at the beginning of Sing.rb.

Regards, Morton

Thufir Hawat

11/7/2007 4:57:00 AM

0

Thanks, Morton :)

Phrogz

11/7/2007 5:05:00 AM

0

On Nov 2, 11:47 pm, m_goldb...@ameritech.net wrote:
> On Nov 3, 2007, at 12:24 AM, Thufir wrote:
>
>
>
> > I need to indicate where to find the Song class. With a module? I'm
> > looking for the simplest technique (hint pls):
>
> > C:\Documents and Settings\nsaunders\Desktop>
> > C:\Documents and Settings\nsaunders\Desktop>
> > C:\Documents and Settings\nsaunders\Desktop>type Song.rb
> > class Song
> > def initialize(name, artist, duration)
> > @name = name
> > @artist = artist
> > @duration = duration
> > end
> > end
> > C:\Documents and Settings\nsaunders\Desktop>
> > C:\Documents and Settings\nsaunders\Desktop>type Sing.rb
> > aSong = Song.new("Bicylops", "Fleck", 260)
> > C:\Documents and Settings\nsaunders\Desktop>
> > C:\Documents and Settings\nsaunders\Desktop>Sing.rb
> > C:/Documents and Settings/nsaunders/Desktop/Sing.rb:1: uninitialized
> > constant So
> > ng (NameError)
>
> > C:\Documents and Settings\nsaunders\Desktop>
> > C:\Documents and Settings\nsaunders\Desktop>
>
> Hint: Insert
>
> require 'Song'
>
> at the beginning of Sing.rb.

Or:
require 'Song.rb'

The point being that you are specifying the name of the _file_ to load
(with or without the .rb extension), not the name of the class. In
your example, they happen to be the same.

Just wanted to be clear about that for your future Ruby programming
endeavors.