what is the error of "uninitialized constant Object::Person (NameError)"?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wiinie
    New Member
    • Feb 2011
    • 47

    what is the error of "uninitialized constant Object::Person (NameError)"?

    Hi all,

    I am new bird using Ruby, I just occur the problem "uninitiali zed constant Object::Person (NameError)"
    can any experts help me?

    my code is
    Code:
    class Person
      def initialize(fname, lname)
        @fname = fname
        @lname = lname
      end
      
      def to_s
        "Person: #@fname #@lname"
      end
    end
    
    person = Person.new("Yen", "Ta")
    print person

    Code:
    class Employee < Person
      def initialize(fname, lname, position)
        super(fname,lname)
        @position = position
      end
      def to_s
         super + ", #@position"
      end
    end
    
    employee = Employee.new("Augustus","Bondi","CFO")
    print employee
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    The 'Employee' file needs to require the 'Person' file. So, for example, at the top of the 'Employee' file, add
    Code:
    require 'path/to/Person'

    Comment

    Working...