Created
May 27, 2015 01:25
-
-
Save kareemgrant/d281d10f4d9a7e4c8c13 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
#1) Create a Robot class | |
#2) add an initialize method that accepts | |
## one attribute "name" | |
#3) Add reader and writer methods (long way) | |
#4) Add a talk method that has the robot say its name | |
#5) Create 3 robots, larry, curly and moe | |
#6) Change curly's name to "shemp" | |
class Robot | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
# def name | |
# @name | |
# end | |
# def name=(new_name) | |
# @name = new_name | |
# end | |
def talk | |
"hello my name is #{name}" | |
end | |
end | |
robot1 = Robot.new("larry") | |
robot2 = Robot.new("curly") | |
robot3 = Robot.new("moe") | |
puts robot1.talk | |
puts robot2.talk | |
puts robot3.talk | |
robot1.name = "shemp" | |
puts robot1.talk | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment