Created
October 7, 2015 20:19
-
-
Save bendoane/a1275320c5677de437c9 to your computer and use it in GitHub Desktop.
Day 3: Like a Robot
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
# Homework - Day 3 | |
# NORMAL MODE----------------------------------------------- | |
# Define a robot class. A robot should have a name | |
class Robot | |
attr_accessor :name | |
attr_accessor :height | |
#creat a robot instance method for saying "hi" | |
def say_hi | |
puts "Greetings" | |
end | |
# create a robot instance for the robot to say its name | |
def say_name | |
puts "My name is \'#{name}\'" | |
end | |
end | |
# define a bending unit class | |
class BendingUnit < Robot | |
#the BendingUnit robot should be able to state he can bend things | |
def bend(object_to_bend) | |
puts "#{name} bends #{object_to_bend}!" | |
end | |
end | |
# define an acting unit class | |
class ActorUnit < Robot | |
#the acting robot should be able to change his name | |
def change_name(new_name) | |
if new_name != @name | |
@name = new_name | |
else | |
puts "That IS my name!" | |
end | |
end | |
end | |
#HARD MODE --------------------------------------- | |
#Take our student array from yesterday and (programmatically) | |
#create robots out of all of them and store them in an array. | |
our_class=["Ben","Anna","Shirley","Lauren","Ben","Michelle","Angie","Matt"] | |
tiy_robots = [] | |
our_class.each do |student| | |
student.downcase! | |
srobot = Robot.new | |
srobot.name = student | |
tiy_robots << srobot | |
end | |
#Do the previous using an Enumerable method other than each | |
roboclass = our_class.collect {|x| srobot = Robot.new; srobot.name = x; srobot} | |
#Robots should also have a height, with a default value of 10 | |
#(***IF COMPLETED - this will have been changed under the class Robot in NORMAL MODE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment