Sign in with
Sign up | Sign in
Your question

Can someone who has enough knowledge on Ruby help me out?

Tags:
  • Apps
  • Edge
  • Ruby
Last response: in Apps General Discussion
Share
April 24, 2014 1:48:33 AM

I need to discuss this source code. Each code and line should be discussed.

#!/usr/local/bin/ruby

row1 = row2 = row3 = ""

edge = "+------+"



top = {

"1" => "| |",

"2" => "| []|",

"3" => "| []|",

"4" => "|[] []|",

"5" => "|[] []|",

"6" => "|[][][]|",

}



middle = {

"1" => "| [] |",

"2" => "| |",

"3" => "| [] |",

"4" => "| |",

"5" => "| [] |",

"6" => "|[][][]|",

}



bottom = {

"1" => "| |",

"2" => "|[] |",

"3" => "|[] |",

"4" => "|[] []|",

"5" => "|[] []|",

"6" => "|[][][]|",

}



$set = Array.new



def roll(times)

count = 0

while count < times

temp = rand(7)

$set.push(temp.to_s) if temp != 0

count += 1 if temp != 0

end

end



times = 1



while times != 0

puts "Please enter the number of times to roll."

puts "Type \"0\" and press enter to quit."

times = gets.chomp.to_i



roll(times)

rolled = $set.length

$set.each do |index|

row1 += top.fetch(index) + " "

row2 += middle.fetch(index) + " "

row3 += bottom.fetch(index) + " "

end



rolled.times{ print edge + " " }

print "\n"

puts row1 + "\n" + row2 + "\n" + row3 + "\n"

rolled.times{ print edge + " " }

print "\n"



$set.clear

row1 = row2 = row3 = ""

end

Thank you!

More about : knowledge ruby

April 24, 2014 1:56:38 AM

This looks like a school project.
m
0
l
April 24, 2014 2:09:47 AM

i7Baby said:
This looks like a school project.

uh,,, yeah. it's a school project, and I need your help.
m
0
l
Related resources
April 24, 2014 5:15:59 AM

What a tedious task.

You're not really asking for anything specific. What about each line needs to be discussed? Have you done any work yourself?
m
0
l
Tom’s guide in the world
  • Germany
  • France
  • Italy
  • Ireland
  • UK
Follow Tom’s guide
Subscribe to our newsletter
  • add to twitter
  • add to facebook
  • ajouter un flux RSS