Optionally evaluate block

on  condition (truthy)

Optionally evaluate the block depending on the truthiness of the supplied condition. The truthiness rules are as follows: all values are seen as true except for: false, nil and 0. Lambdas will be automatically called and the truthiness of their results used.

Introduced in v2.10

Examples

# Example 1

on true do
  play 70    
end



 
#=> will play 70 as true is truthy
 



# Example 2

on 1 do
  play 70    
end



 
#=> will play 70 as 1 is truthy
 



# Example 3

on 0 do
  play 70    
end



 
#=> will *not* play 70 as 0 is not truthy
 



# Example 4

on false do
  play 70    
end



 
#=> will *not* play 70 as false is not truthy
 



# Example 5

on nil do
  play 70    
end



 
#=> will *not* play 70 as nil is not truthy
 



# Example 6

on lambda{true} do
  play 70    
end



 
#=> will play 70 as the lambda returns a truthy value
 



# Example 7

on lambda{false} do
  play 70    
end



 
#=> will *not* play 70 as the lambda does not return a truthy value
 



# Example 8

on lambda{[true, false].choose} do
  play 70    
end



 
#=> will maybe play 70 depending on the choice in the lambda