forked from fjordllc/bug_cafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cafe.rb
34 lines (28 loc) · 1.04 KB
/
cafe.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true
DRINKS = [
{ name: 'コーヒー', price: '300' },
{ name: 'カフェラテ', price: '400' },
{ name: 'チャイ', price: '460' },
{ name: 'エスプレッソ', price: '340' },
{ name: '緑茶', price: '450' }
].freeze
FOODS = [
{ name: 'チーズケーキ', price: '470' },
{ name: 'アップルパイ', price: '520' },
{ name: 'ホットサンド', price: '410' }
].freeze
def take_order(menus)
menus.each.with_index(1) do |menu, i|
puts "(#{i})#{menu[:name]}: #{menu[:price]}円"
end
print '>'
order_number = gets.to_i
puts "#{menus[order_number - 1][:name]}(#{menus[order_number - 1][:price]}円)ですね。"
order_number
end
puts 'bugカフェへようこそ!ご注文は? 番号でどうぞ'
drink_order_num = take_order(DRINKS)
puts 'フードメニューはいかがですか?'
food_order_num = take_order(FOODS)
total = DRINKS[drink_order_num - 1][:price].to_i + FOODS[food_order_num - 1][:price].to_i
puts "お会計は#{total}円になります。ありがとうございました!"