開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Ruby 2.3 (プログラミング言語)
Head First Ruby (Jay McGavren (著)、O'Reilly Media)のChapter 2.(Methods and Classes: Getting Organized)、POOL PUZZLE(No. 1424)を取り組んでみる。
POOL PUZZLE(No. 1424)
コード(Emacs)
#!/usr/bin/env ruby2.3
# -*- coding: utf-8 -*-
class Robot
def head
@head
end
def arms=(value)
@arms = value
end
attr_reader :legs, :body
attr_writer :eyes
attr_accessor :feet
def assemble
@legs = "RubyTek Wlkers"
@body = "BurlyBot Frame"
@head = "SuperAI 9000"
end
def diagnostic
puts @arms
puts @eyes
end
end
robot = Robot.new
robot.assemble
robot.arms = "MagGrip Claws"
robot.eyes = "X-Ray Scopes"
robot.feet = "MagGrip Boots"
puts robot.head
puts robot.legs
puts robot.body
puts robot.feet
robot.diagnostic
入出力結果(Terminal)
$ ./sample3.rb SuperAI 9000 RubyTek Wlkers BurlyBot Frame MagGrip Boots MagGrip Claws X-Ray Scopes $
0 コメント:
コメントを投稿