Could someone explain why the following code raises ArgumentError. Thanks.
class SuperClass
def initialize #Make sure you spell 'initialize' correctly!
@my_attr = 1
end
attr_reader :my_attr
end
class SubClass < SuperClass
def initialize(data1, data2)
super
@data1 = data1
@data2 = data2
end
attr_reader :data1
attr_reader :data2
end
test = SubClass.new("one", "two")
puts test.my_attr
puts test.data1
puts test.data2
$ ruby inheritance_problem.rb
inheritance_problem.rb:13:in `initialize': wrong number of arguments
(2 for 0) (ArgumentError)
from inheritance_problem.rb:13:in `initialize'
from inheritance_problem.rb:23:in `new'
from inheritance_problem.rb:23