2016年9月9日金曜日

開発環境

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 コメント:

コメントを投稿