Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed cafe bug #26

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cafe.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
# require 'debug'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提出物からはコメントアウトでなくて消しましょう


DRINKS = [
{ name: 'コーヒー', price: '300' },
Expand All @@ -15,11 +16,12 @@
].freeze

def take_order(menus)
# binding.break
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上です。提出物からは消しましょう

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました。

menus.each.with_index(1) do |menu, i|
puts "(#{i})#{menu[:name]}: #{menu[:price]}円"
end
print '>'
order_number = gets.to_i
order_number = gets.to_i - 1
puts "#{menus[order_number][:name]}(#{menus[order_number][:price]}円)ですね。"
order_number
end
Expand All @@ -30,5 +32,5 @@ def take_order(menus)
puts 'フードメニューはいかがですか?'
order2 = take_order(FOODS)

total = FOODS[order1][:price] + DRINKS[order2][:price]
total = FOODS[order2][:price].to_i + DRINKS[order1][:price].to_i
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これでOKです。しかし本質的にはorder1,2のようなわかりにくい命名が引き起こしがちな不具合ともいえます。したがってよりよい解答としては変数名の見直しまでするといいですね。修正は任意で結構です。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました!今のコードはorder1はdrinkorderになって、食べ物の分はfoodorderになりました。

puts "お会計は#{total}円になります。ありがとうございました!"