Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created October 27, 2010 01:50
Show Gist options
  • Save rjungemann/648248 to your computer and use it in GitHub Desktop.
Save rjungemann/648248 to your computer and use it in GitHub Desktop.
Silly dice class for teaching purposes
class Dice
attr_accessor :sides
# set "sides" to default to 6
def initialize
self.sides = 6
end
# take a random number from 0 to 1, multiply by number of sides,
# then round up
def roll
(rand * self.sides).ceil
end
end
dice = Dice.new
puts "Dice rolled " + dice.roll.to_s
puts "Dice rolled " + dice.roll.to_s
puts "Dice rolled " + dice.roll.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment