class Cal
attr_reader :v1, :v2
attr_writer :v1
@@_history = []
def initialize(v1,v2)
@v1 = v1
@v2 = v2
end
def add()
result = @v1+@v2
@@_history.push("add : #{@v1}+#{@v2}=#{result}")
return result
end
def subtract()
result = @v1-@v2
@@_history.push("subtract : #{@v1}-#{@v2}=#{result}")
return result
end
def setV1(v)
if v.is_a?(Integer)
@v1 = v
end
end
def getV1()
return @v1
end
def Cal.history()
for item in @@_history
p item
end
end
def info()
return "Cal => v1 : #{@v1}, v2 : #{@v2}"
end
end
class CalMultiply < Cal
def multiply()
result = @v1*@v2
@@_history.push("multipy : #{@v1}*#{@v2}=#{result}")
return result
end
def info()
return "CalMultiply => #{super()}"
end
end
class CalDivide < CalMultiply
def divide()
result = @v1/@v2
@@_history.push("divide : #{@v1}/#{@v2}=#{result}")
return result
end
def info()
return "CalDivide => #{super()}"
end
end
c0 = Cal.new(30, 60)
p c0.info()
c1 = CalMultiply.new(10, 10)
p c1.info()
c2 = CalDivide.new(20, 10)
p c2.info()
Y2xhc3MgQ2FsCiAgYXR0cl9yZWFkZXIgOnYxLCA6djIKICBhdHRyX3dyaXRlciA6djEKICBAQF9oaXN0b3J5ID0gW10KICBkZWYgaW5pdGlhbGl6ZSh2MSx2MikKICAgIEB2MSA9IHYxCiAgICBAdjIgPSB2MgogIGVuZAogIGRlZiBhZGQoKQogICAgcmVzdWx0ID0gQHYxK0B2MgogICAgQEBfaGlzdG9yeS5wdXNoKCJhZGQgOiAje0B2MX0rI3tAdjJ9PSN7cmVzdWx0fSIpCiAgICByZXR1cm4gcmVzdWx0CiAgZW5kCiAgZGVmIHN1YnRyYWN0KCkKICAgIHJlc3VsdCA9IEB2MS1AdjIKICAgIEBAX2hpc3RvcnkucHVzaCgic3VidHJhY3QgOiAje0B2MX0tI3tAdjJ9PSN7cmVzdWx0fSIpCiAgICByZXR1cm4gcmVzdWx0CiAgZW5kCiAgZGVmIHNldFYxKHYpCiAgICBpZiB2LmlzX2E/KEludGVnZXIpCiAgICAgI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