szatan
szatan

Reputation: 517

Object as variable in new class? Ruby

I'am doing some begginer type OOP exercises found in internet. Currently my task is to create two classes:

Problem is how to create this Person type variable. I tried this:

class Person
  attr_accessor :name, :surname, :age

  def initialize name, surname, age = nil
    @name, @surname, @age = name, surname, age
  end
end


class Song
  attr_accessor :tite, :author, :date_of_issue

  def initalize title, author , date_of_issue
    @title, @author, @date_of_issue = title, Person.new, date_of_issue
  end
end

When I try to create new object:

 song1 = Song.new("All_you_need_is_love", "The_beattles", 1967)

I get:

ArgumentError: wrong number of arguments (0 for 2)

So I got two ideas:

  1. My Song class code is wrong

  2. song1 object initialization is wrong (because number of arguments)

What do you think?

Upvotes: 0

Views: 96

Answers (1)

flq
flq

Reputation: 22839

You should spell initialize properly in Song. Also consider that the Person constructor requires at least 2 arguments.

Upvotes: 2

Related Questions