I’m trying to create a number of objects from a class.
class Class
def initialize (name=nil, age = nil, weight = nil)
@name = name
@age = age
@weight = weight
end
end
p1 = Class.new("Joe", 12, 135)
p2 = Class.new("Jack", 29, 200)
The problem is that the objects are not going to hold the same number of parameter. If I try to create a person that “does’nt have” a weight:
p3 = Class.new("Jill", 44)
This will affect the previously created objects, by removing their wheight as well, which is not what I intended to do. Is there a way to get around this, closing classes?
Or am I missing something vital?
My IRB session:
As you see there is no global override of
@weight.