From: Matthew Kerwin Date: 2012-07-20T13:17:15+09:00 Subject: Re: unless if not == unless post_on_ruby_forum It's most useful for perl-esque one-liners: die unless it_worked On 20 July 2012 14:05, roob noob wrote: > So everything I have thus far read and heard about the Ruby unless > keyword lead me to believe that it is just another word for if not. This > is not true. > > unless 1 + 1 == 2 > puts "a" > elsif 1 + 1 == 5 > puts "b" > else > puts "c" > end > > this code fails and complains that it expects an end to be where elsif > is > however > > if not 1 + 1 == 2 > puts "a" > elsif 1 + 1 == 5 > puts "b" > else > puts "c" > end > > works as expected. This took me quite a while to figure out as everyone > had always lead me to believe that unless is just the cool kids way of > saying if not in ruby. > > So I guess my question is, are there any other unexpected behaviors of > unless that I should know about? I think I might just start using if not > and ignoring unless, I actually end up having to translate it to if not > in my head anyway to read things clearly, and it doesn't work with > elsif. Why does everyone rave about how unless is exactly like if not > but with clearer language, if this is not the case ? > > -- > Posted via http://www.ruby-forum.com/. > -- Matthew Kerwin, B.Sc (CompSci) (Hons) http://matthew.kerwin.net.au/ ABN: 59-013-727-651 "You'll never find a programming language that frees you from the burden of clarifying your ideas." - xkcd