Uninitialized constant Customer (NameError)


#1

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…


#2

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


#3

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


#4

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