Forum: Ruby uninitialized constant Customer (NameError)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gopal P. (Guest)
on 2006-04-11 21:14
Hi everybody,
I created a class called Customer and created a sub class called
Transaction. The problem iam facing is i can't extract the super class
methods and variables from sub class (i.e from Transaction class).
the error it shows is

ruby Transaction.rb
Transaction.rb:1: uninitialized constant Customer (NameError)
>Exit code: 1

please let me know how do i proceed.....

Thanks in advance......
Austin Z. (Guest)
on 2006-04-11 22:05
(Received via mailing list)
On 4/11/06, gopal pusuluri <removed_email_address@domain.invalid> wrote:
> please let me know how do i proceed.....
1. Some actual code might help.
2. Huh?

-austin
Pit C. (Guest)
on 2006-04-11 22:46
(Received via mailing list)
gopal pusuluri schrieb:
> Hi everybody,
> I created a class called Customer and created a sub class called
> Transaction. The problem iam facing is i can't extract the super class
> methods and variables from sub class (i.e from Transaction class).
> the error it shows is
>
> ruby Transaction.rb
> Transaction.rb:1: uninitialized constant Customer (NameError)
>
>>Exit code: 1

Since you get the error in line 1 of the Transaction.rb file, I guess it
starts with

   class Transaction < Customer

and I guess you define the class Customer in a file Customer.rb. If I'm
correct, you first have to require the file with the Customer class, so
your file Transaction.rb has to start with

   require "Customer"
   class Transaction < Customer

Some further remarks:

* You don't need to name the file after the class. And you don't have to
define each class in its own file. For example, you could define both of
your classes in a file called "app.rb".

* I think Filenames with mixed uppercase and lowercase letters aren't
often used in Ruby land.

* How can a transaction be a subclass of a customer?

Regards,
Pit
Gopal P. (Guest)
on 2006-04-12 15:11
Hi Mr.Pit
Thanks for the solid information that u posted, yes the require
"Customer" is the sentence which i missed out.....

Thanks again for ur info,,,
bye

Pit C. wrote:
> gopal pusuluri schrieb:
>> Hi everybody,
>> I created a class called Customer and created a sub class called
>> Transaction. The problem iam facing is i can't extract the super class
>> methods and variables from sub class (i.e from Transaction class).
>> the error it shows is
>>
>> ruby Transaction.rb
>> Transaction.rb:1: uninitialized constant Customer (NameError)
>>
>>>Exit code: 1
>
> Since you get the error in line 1 of the Transaction.rb file, I guess it
> starts with
>
>    class Transaction < Customer
>
> and I guess you define the class Customer in a file Customer.rb. If I'm
> correct, you first have to require the file with the Customer class, so
> your file Transaction.rb has to start with
>
>    require "Customer"
>    class Transaction < Customer
>
> Some further remarks:
>
> * You don't need to name the file after the class. And you don't have to
> define each class in its own file. For example, you could define both of
> your classes in a file called "app.rb".
>
> * I think Filenames with mixed uppercase and lowercase letters aren't
> often used in Ruby land.
>
> * How can a transaction be a subclass of a customer?
>
> Regards,
> Pit
This topic is locked and can not be replied to.