Submission Status: Passed
Submitted for: January 22 - Build a Tip Calculator in Ruby that Can Accept Multiple Data Types as Input
Submitted at: August 01, 2017
class String def integer? return true if self =~ /^[1-9]\d*(\.\d+)?$/ false end end module Tippy class Builder def initialize total:, gratuity: @total = total @gratuity = gratuity end def generate return calculation if number_based? string_based end def number_based? (@gratuity.is_a? Numeric) || (@gratuity.integer?) end def string_based case @gratuity.downcase when 'high' then calculation 25 when 'standard' then calculation 18 when 'low' then calculation 15 end end def calculation gratuity = @gratuity @total += @total * (gratuity.to_f / 100) end end end
devCamp does not support ancient browsers.
Install a modern version for best experience.