Conversation
CalculatorWhat We're Looking For
Good work overall! You make good use of whitespace to break up your code into sections. I've left a few inline comments below for you to review, but in general I am quite happy with this submission. |
| # method to verify user input - integer | ||
| def integer? | ||
| Integer(gets) rescue false | ||
| end |
There was a problem hiding this comment.
You've named this method integer? with a question mark, which implies that it should return a Boolean (true or false). However it looks like it returns the user's input as an integer. A better name for this method might be something like parse_input.
| # check for valid user input | ||
| until first | ||
| number_reprompt | ||
| first = integer? |
There was a problem hiding this comment.
You've written almost exactly the same code here twice, to get the first number and the second number. Could you DRY that up by putting this logic in a method?
| case op | ||
|
|
||
| when "add", "+" | ||
| puts "#{first} + #{second} = #{first + second}" |
There was a problem hiding this comment.
This code isn't repeated, but I think it would still increase readability to wrap this case/when section in a method. That would clearly delineate where it starts and ends, and make it explicit what data it needs to work. The method signature might be something like perform_calculation(op, first, second).
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions