-
-
Save abrahamsangha/5547003 to your computer and use it in GitHub Desktop.
Implement a basic Die class which can be initialized with some number of sides. We can then roll the die, returning a random number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Die | |
| def initialize(sides) | |
| raise ArgumentError.new("Need at least one side") unless sides >= 1 | |
| @sides = sides | |
| end | |
| def sides | |
| @sides | |
| end | |
| def roll | |
| rand(sides) + 1 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment