-
Notifications
You must be signed in to change notification settings - Fork 0
Print the correct total price #1
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
base: main
Are you sure you want to change the base?
Conversation
* cafe.rb: Change ":price" values to Integer objects, and sum the prices of the selected menus. (take_order): Choose the correct menu.
JunichiIto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1点コメントしました〜。
cafe.rb
Outdated
| until (order_number ||= -1).between?(0, menus.size - 1) | ||
| print '>' | ||
| order_number = gets.to_i - 1 | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| until (order_number ||= -1).between?(0, menus.size - 1) | |
| print '>' | |
| order_number = gets.to_i - 1 | |
| end | |
| begin | |
| print '>' | |
| order_number = gets.to_i - 1 | |
| end while menus[order_number].nil? |
こんな感じにした方がシンプルかつコードの意図が明確になるかな?と思いますがいかがでしょう?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レビューしていただき、ありがとうございます。
begin...end whileのほうが読みやすいと感じます。
修正して実行してみたところ、Rubyの配列の仕様により、order_numberが- menus.size + 1以上0以下の整数でも動作しました。これは許容しても良いのでしょうか?
自分としては、提示されたメニューの番号を入力すべきだと考えていますが、begin...end until (または while !) order_number.between?(0, menus.size - 1)では意図が伝わりにくいでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、たしかにwhile menus[order_number].nil?だと元のコードと挙動が異なりますね。
end until (または while !) order_number.between?(0, menus.size - 1) みたいな感じで良いと思います!
ちなみにGitHubのコメント通知はほかの通知メールに埋もれて気づけないときがあるので、今後は念のためFBC側のコメント欄でも「PRで質問してます」みたいな連絡をもらえると助かります〜 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、たしかに
while menus[order_number].nil?だと元のコードと挙動が異なりますね。end until (または while !) order_number.between?(0, menus.size - 1)みたいな感じで良いと思います!
ありがとうございます!
コードを修正した後、pushします。
ちなみにGitHubのコメント通知はほかの通知メールに埋もれて気づけないときがあるので、今後は念のためFBC側のコメント欄でも「PRで質問してます」みたいな連絡をもらえると助かります〜 🙏
承知しました。コメント欄のほうにも記入するようにします。
* cafe.rb (take_order): Change until statement to begin statement with until modifier.
|
@JunichiIto コードを修正しました! |
JunichiIto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確認しました!OKです〜🙆♂️
(take_order): Choose the correct menu.