Build a Tip Calculator in Ruby that Can Accept Multiple Data Types as Input


In this coding exercise we’ll build out an extensive tip calculator that can accept integers, string based numbers and even words to dynamically generate a tip.


Build a Ruby module that can accurately process tip amounts based on input with multiple data type options.

Exercise File

Code File

Exercise Description

The key to this exercise is understanding how to properly manage multiple data type inputs and then to process the tip calculations.

Example Behavior 100, gratuity: '23.5').generate # 123.5 100, gratuity: 'high').generate # 125.0 100, gratuity: 'LOW').generate # 115.0 100, gratuity: 'standard').generate # 118.0 100, gratuity: '18').generate # 118.0 100, gratuity: 20).generate # 120.0 100, gratuity: 0).generate # 100.0

Please note that you need to handle:

  • Parsing string based numbers such as '20'
  • Traditional integers
  • Words, such as high, standard, and low. You can look at the tests to figure out what percentages those words should represent.

Real World Usage

This is going to be a challenging exercise that will test a number of coding techniques, such as:

  • Working with modules and classes
  • Performing metaprogramming
  • Control flow for varying data types
  • Regular expressions

Each of these components are utilized in day to day development.


Can be found on the solutions branch on github.


  1. Not everyone would agree to the hard coded values you have for the string types. Please consider some kind of configuration options that the user could set. Thanks again Jordan!


Please enter your comment!
Please enter your name here