Sinatra

After studying the ruby ​​for a month, I decided to move to Sinatra. I need help understanding an Sinatra fragment that illustrates conditions and routing. Can someone clearly explain what happens in turn, and how does this block actually randomize the route?

set(:probability) { |value| condition { rand <= value } }

  get '/win_a_car', :probability => 0.1 do
    "You won!"
  end

  get '/win_a_car' do
    "Sorry, you lost."
  end
+5
source share
1 answer

The general behavior of this will result in the first route being loaded approximately 10% of the time, and the second route being loaded the rest of the time.

, . , # 0-1 . 0,1, 10% .

90% , . , .

, Proc.

: http://www.sinatrarb.com/intro#Conditions

+7

All Articles