Your problem is that you refer to @options
, but you don't assign it when creating an instance of Celsius
. You should call the super
constructor in your inherited classes:
class Celsius < Temperature
def initialize(num)
super(c: num)
end
end
class Fahrenheit < Temperature
def initialize(num)
super(f: num)
end
end
Now, when you call Celsius.new(50)
the initialize(opts)
will be called as if you called Temperature.new(c: 50)
, and all members will be properly assigned.