Skip to content

Instantly share code, notes, and snippets.

@kareemgrant
Created May 27, 2015 01:25
Show Gist options
  • Select an option

  • Save kareemgrant/d281d10f4d9a7e4c8c13 to your computer and use it in GitHub Desktop.

Select an option

Save kareemgrant/d281d10f4d9a7e4c8c13 to your computer and use it in GitHub Desktop.

Revisions

  1. kareemgrant created this gist May 27, 2015.
    45 changes: 45 additions & 0 deletions robot.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #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