Ruby switch statement always evaluates to default -


if simulate rolling of six-sided die follows, evaluates 6. how fix this?

def rolldice()   roll = rand()   case roll     when 0..(1/6) return 1     when (1/6)..(2/6) return 2     when (2/6)..(3/6) return 3     when (3/6)..(4/6) return 4     when (4/6)..(5/6) return 5     else return 6   end end  die1 = rolldice() puts die1 

this because 1/6 0. can pass range rand:

def rolldice   rand(1..6) end 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -