Hey everyone. New R. user here. I am trying to create a dice class
that adds the rolled values (a string) into a list. Here’s what I have
so far:
class Die
def initialize(rolls)
@rolled_values = []
@rolls = rolls
end
def roll
@rolls.times do
rolled_value =
“#{rand(1…6)}#{rand(1…6)}#{rand(1…6)}#{rand(1…6)}#{rand(1…6)}”
@rolled_values.push(rolled_value)
end
end
def print_values
puts @rolled_values
end
end
if FILE == $0
test_roll = Die.new(5)
test_roll.roll
test_roll.print_values
end
Here’s an example of what I’m expecting:
[‘13432’, ‘21232’, ‘43612’, ‘44341’, ‘66345’]
Here’s what I’m getting:
13432
21232
43612
44341
66345
What am I doing wrong? Please explain.