Skip to content

Instantly share code, notes, and snippets.

@abrahamsangha
Created May 9, 2013 11:46
Show Gist options
  • Select an option

  • Save abrahamsangha/5547003 to your computer and use it in GitHub Desktop.

Select an option

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.
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