Unless

ruby

#1

i can't really understand how to use the unless statements


#2

It works exactly like an if statement except the opposite, so if you would like to say 'If the user doesn't say "Nope!", then do x.' then you could do it

unless user_input == "Nope!"
    x
end

or you could do it

if user_input != "Nope!"
    x
end

It is just another part of the extreme flexibility of Ruby, allowing you to do the same thing many different ways.