Created
June 28, 2013 19:07
-
-
Save tarynsauer/5887232 to your computer and use it in GitHub Desktop.
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(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