Skip to content

Instantly share code, notes, and snippets.

@brittanmcg
Created December 6, 2013 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brittanmcg/7818111 to your computer and use it in GitHub Desktop.
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 …
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