開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Ruby 2.3 (プログラミング言語)
Head First Ruby (Jay McGavren (著)、O'Reilly Media)のChapter 12.(Exceptions: Handling the Unexpected)、Exception messages、CODE MAGNETS(No. 6309)を取り組んでみる。
CODE MAGNETS(No. 6309)
コード(Emacs)
#!/usr/bin/env ruby2.3
# -*- coding: utf-8 -*-
def drive(destination)
if destination == "Hawaii"
raise "You can't drive to Hawaii!"
end
end
begin
drive("Hawaii")
rescue => error
puts error.message
end
入出力結果(Terminal)
$ ./sample1.rb You can't drive to Hawaii! $
0 コメント:
コメントを投稿