Skip to content

Instantly share code, notes, and snippets.

@tarynsauer
Created June 28, 2013 19:07
Show Gist options
  • Save tarynsauer/5887232 to your computer and use it in GitHub Desktop.
Save tarynsauer/5887232 to your computer and use it in GitHub Desktop.
class Die
def initialize(labels)
@labels = labels
end
def sides
@labels.length
end
def roll
if @labels == []
raise ArgumentError.new("Labels list is empty")
end
count = (0..@labels.length).to_a
hash = Hash[count.zip @labels]
hash[rand(@labels.length)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment