Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment