Ruby/Statement/if as modifier

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

change the order: placing if after puts, and you can drop then and end.

x = 256
puts "x equals 256" if x == 256



If the value of age is under 18, the string is printed to the screen.

age = 10
puts "You"re too young to use this system" if age < 18
age = 10
if age < 18
  puts "You"re too young to use this system"
end



Output based on if statement

age = 24
puts "You"re a teenager" if age > 12 && age < 20



test for equality:

age = 24
puts "You"re 24!" if age == 24



using if as a modifier with Boolean operator

temperature = 76
puts "Picnic time!" if temperature > 65 && temperature < 85