Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. class Dice
  2. attr_accessor :sides
  3.  
  4. # set "sides" to default to 6
  5. def initialize
  6. self.sides = 6
  7. end
  8.  
  9. # take a random number from 0 to 1, multiply by number of sides,
  10. # then round up
  11. def roll
  12. (rand * self.sides).ceil
  13. end
  14. end
  15.  
  16. dice = Dice.new
  17.  
  18. puts "Dice rolled " + dice.roll.to_s
  19. puts "Dice rolled " + dice.roll.to_s
  20. puts "Dice rolled " + dice.roll.to_s
Add Comment
Please, Sign In to add comment