loading...

re: Daily Challenge #241 - Tip Calculator VIEW POST

TOP OF THREAD FULL DISCUSSION
re: RATINGS = { terrible: 0, poor: 5, good: 10, great: 15, excellent: 20 }.freeze def calculatetip(bill, service) service = service....
 

Some minor suggestions:

  1. Move ratings out of the method, no need to recreate it.
  2. You can try to retrieve the service and do a nil check instead of checking keys, which seems to be more common in Ruby code in the wild.
  3. Floats are "viral", introducing one into the calculation makes all to_f calls redundant.
RATINGS = {
  terrible: 0,
  poor: 5,
  good: 10,
  great: 15,
  excellent: 20
}.freeze

def calculate_tip(bill, service)
  service = RATINGS[service.downcase.to_sym]
  return 'Rating Not Recognized' unless service

  (bill * service / 100.0).ceil
end
code of conduct - report abuse