-
-
Save brittanmcg/7818111 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. It should work like this: die = Die.new(6)
die.sides # returns 6
die.roll # returns a random number between 1 and 6
If we pass Die.new a number less than 1, we should raise an ArgumentError. This is done using the …
This file contains 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) | |
# code goes here | |
@sides = sides | |
if sides < 1 | |
raise ArgumentError.new("Please input a number 1 or larger.") | |
end | |
end | |
def sides | |
# code goes here | |
random = rand(max= @sides) | |
end | |
def roll | |
# code goes here | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment