Skip to content

Instantly share code, notes, and snippets.

@utumno86
Last active August 29, 2015 14:20
Show Gist options
  • Save utumno86/95528a74f085c67b534b to your computer and use it in GitHub Desktop.
Save utumno86/95528a74f085c67b534b to your computer and use it in GitHub Desktop.
Iron Yard Homework Solution Repo
class Robot
def initialize(name)
@name=name
end
def say_hi
puts "Hi!"
end
def say_name
puts "My name is #{@name}"
end
end
robotIV = Robot.new("Prince Robot IV")
robotIV.say_hi
robotIV.say_name
class Attack_Robot < Robot
def say_name
puts "My name is #{@name}, and I'm here to kill Sarah Connor."
end
end
terminator = Attack_Robot.new("The Terminator")
terminator.say_hi
terminator.say_name
#Create a ruby file named robot.rb
#Define a Robot class
#A robot should have a name.
#A robot should have a method called say_hi and it should return "Hi!"
#A robot should have a method called say_name and it should return "My name is X" where X is the robot's name.
#Create an instance of your robot and add some demonstrations of your it's features at the end of the file.
#Bonus
#Define a new type of robot that inherits from your first Robot class.
#Have your new robot class do say_name in a different way than the original.
#Add some demonstrations of your new robot's features at the end of the file as well.
#Close this issue to notify me for review. Be sure to include a link to your solution.
class Robot
T1000 = :t1
HAL = :h1
#these are constants
def initialize(name, type = :t1)
@name=name
@type=type
end
def say_hi
puts "Hi!"
end
def say_name
puts "My name is #{@name}"
end
def name
@name
end
def type
@type
end
end
robotIV = Robot.new("Prince Robot IV")
class Attack_Robot < Robot
def say_name
puts "My name is #{@name}, and I'm here to kill Sarah Connor."
end
end
terminator = Attack_Robot.new("The Terminator")
#Create a ruby file named robot.rb
#Define a Robot class
#A robot should have a name.
#A robot should have a method called say_hi and it should return "Hi!"
#A robot should have a method called say_name and it should return "My name is X" where X is the robot's name.
#Create an instance of your robot and add some demonstrations of your it's features at the end of the file.
#Bonus
#Define a new type of robot that inherits from your first Robot class.
#Have your new robot class do say_name in a different way than the original.
#Add some demonstrations of your new robot's features at the end of the file as well.
#Close this issue to notify me for review. Be sure to include a link to your solution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment