Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neelmanishankar/b1191922a8fa6ec5b56529c4b29b4e95 to your computer and use it in GitHub Desktop.
Save neelmanishankar/b1191922a8fa6ec5b56529c4b29b4e95 to your computer and use it in GitHub Desktop.
class Thing
def initialize (aName, aDescription)
@name = aName
@description = aDescription
end
def get_name
return @name
end
def set_name (aName)
@name = aName
end
def get_description
return @description
end
end
class Treasure < Thing # Treasure descend from Thing
def initialize (aName, aDescription, aValue)
super(aName,aDescription) #<-------- ERROR HERE
@value = aValue
end
def get_value
return @value
end
def set_value (aValue)
@value = aValue
end
def set_description (aDescription)
@description = aDescription
end
end
# This is where our program start...
t1 = Treasure.new("Sword", "an Elvish weapon forge of gold",800)
t2 = Treasure.new("Dragon Horde", "a huge pile of jewels", 550)
puts "This is treasure1 : #{t1.inspect}"
puts "This is treasure1 : #{t2.inspect}"
puts "t1 name=#{t1.get_name}, description=#{t1.get_description}, value=#{t1.get_value}"
t1.set_value(100)
t1.set_description ("(now somewhat tarnish)")
puts "t1 (NOW) name= #{t1.get_name}, description=#{t1.get_description}, value=#{t1.get_value}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment