true
and false
are unique objects (technically instances of TrueClass
and FalseClass
)
They are the result of comparison operators
>
Greater than?>=
Greater than or equal to?<
Less than?<=
Less than or equal to?==
Equal?!=
Not equal?
1 > 0
# => true
"hello" == "hello"
# => true
if
and else
allow you to control the flow of your program. The concept is pretty simple,
read the following, you should be able to get a good idea of what the program will do
puts "Hey! What’s your name?"
response = gets.chomp
if response.downcase == 'computer'
puts "Weird, that's my name too. Small world!"
else
puts "Wacky name!"
end
puts "Well, it was nice to meet you #{response}."