開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Ruby 2.3 (プログラミング言語)
Head First Ruby (Jay McGavren (著)、O'Reilly Media)のChapter 3.(Inheritance: Relying on Your Parents)、Overriding methods、POOL PUZZLE(No. 1756)を取り組んでみる。
POOL PUZZLE(No. 1756)
コード(Emacs)
#!/usr/bin/env ruby2.3
# -*- coding: utf-8 -*-
class Camera
def load
puts "Winding film."
end
def take_picture
puts "Triggering shutter."
end
end
class DigitalCamera < Camera
def load
puts "Inserting memory card."
end
end
camera = Camera.new
camera.load
camera.take_picture
camera2 = DigitalCamera.new
camera2.load
camera2.take_picture
入出力結果(Terminal)
$ ./sample1.rb Winding film. Triggering shutter. Inserting memory card. Triggering shutter. $
0 コメント:
コメントを投稿