Ruby – If-Else Statements and other conditional statements

Here’s a simply if-else statement:

a_number = 15

if a_number > 10
  puts "this is a big  number"
else
  puts "this is a small number"
end

# the above outputs: "this is a big  number"

Another way to write the above is to capture the if-else statements output into a variable like this:

a_number = 15

result = if a_number > 10
  "this is a big  number"
else
  "this is a small number"
end

puts result

# the above outputs: "this is a big  number"