Building validations in programs is a common requirement. In this exercise we’ll examine how to ensure a set of dice are valid by implementing a method that returns false if the dice are outside the range of 1-6.
Build a dice validator program.
Implement a program that checks to see if a roll of two dice is valid or not.
valid_dice? 4, 2 # => true valid_dice? 6, 6 # => true valid_dice? 5, 1 # => true valid_dice? 8, 2 # => false valid_dice? 1, 7 # => false valid_dice? 9, 7 # => false
Real World Usage
Working with range based validations are a common requirement for a wide variety of applications. Imagine a situation where you need to see if a user’s zip code falls inside of a certain range of numbers. There are a number of ways to implement this solution, I personally opted for the version that worked with collections of data.
Can be found on the solutions branch on github.