Reputation: 217
The program below is an attempt to take in an American president, and French President's age, and name. The catch is that the French president says "bein sur" afterward calling his name, age and citizenship (not my idea). I'm having trouble with the French president's catchphrase. Here's my code
class President
attr_accessor :name, :age
def initialize(name, age)
@name = name
@age = age
end
def name=(name) # setter
@name = name
end
def name # getter
@name
end
def age=(age)
@age = age
end
def age
@age
end
end
class FrancePresident < President
def self.citizenship
"La France"
end
def initialize(name, age)
super(name)
super(age)
end
def catchphrase
"bein sur"
end
end
class UnitedStatesPresident < President
def self.citizenship
"The Unites States of America"
end
end
The instance method I have for his catch phrase is the last attempt out of many to get this guy to say this phrase, but it's incomplete, I think I'm supposed to define calls to the super class for getting his name and age, but I'm unsure of how to get past this argument error.
ArgumentError
wrong number of arguments (1 for 2)
exercise.rb:4:in `initialize'
exercise.rb:32:in `initialize'
exercise_spec.rb:24:in `new'
exercise_spec.rb:24:in `block (3 levels) in <top (required)>'
I'm new to ruby, so any hints or suggestions will be greatly appreciated.
Upvotes: 1
Views: 164
Reputation: 12568
Replace this:
super(name)
super(age)
with this:
super(name, age)
The initialize
method in President
takes two parameters, not one.
You could even remove the arguments, and the parameters will be passed by default:
super
Better yet, just remove the entire initalize
method in subclasses of President
, because it is inherited.
Upvotes: 2