PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > new instance (uninitialized constant)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
new instance (uninitialized constant)

Réponse
 
LinkBack Outils de la discussion
Vieux 03/11/2007, 06h24   #1
hawat.thufir@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut new instance (uninitialized constant)

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


  Réponse avec citation
Vieux 03/11/2007, 08h47   #2
m_goldberg@ameritech.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: new instance (uninitialized constant)

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

  Réponse avec citation
Vieux 07/11/2007, 05h56   #3
Thufir
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: new instance (uninitialized constant)

Thanks, Morton

  Réponse avec citation
Vieux 07/11/2007, 06h04   #4
Phrogz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: new instance (uninitialized constant)

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.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h24.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,83120 seconds with 12 queries