2016年8月19日金曜日

開発環境

Head First Ruby (Jay McGavren (著)、O'Reilly Media)のChapter 6.(Block Return Values: How Should I Handl This?)、Blocks have a return value、CODE MAGNETS(No. 3625)を取り組んでみる。

CODE MAGNETS(No. 3625)

コード(Emacs)

#!/usr/bin/env ruby2.3
# -*- coding: utf-8 -*-


def make_casserole
  puts "Preheat oven to 375 degrees"
  ingredients = yield
  puts "Place #{ingredients} in dish"
  puts "Bake for 20 minutes"
end

make_casserole do
  "noodles, celery, and tuna in dish"
end

make_casserole do
  "rice, broccoli, and chicken in dish"
end

入出力結果(Terminal)

$ ./sample2.rb
Preheat oven to 375 degrees
Place noodles, celery, and tuna in dish in dish
Bake for 20 minutes
Preheat oven to 375 degrees
Place rice, broccoli, and chicken in dish in dish
Bake for 20 minutes
$

0 コメント:

コメントを投稿