Created
April 22, 2017 17:20
-
-
Save neelmanishankar/b1191922a8fa6ec5b56529c4b29b4e95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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