From: Todd Benson Date: 2008-05-03T22:16:28+09:00 Subject: Re: a ? b : c On Sat, May 3, 2008 at 8:01 AM, luka luka wrote: > Hi all! > please explain, what is it? what he is doing? > example: > > x = 6 > y = x == 5 ? 0 : 2 > puts y // prints 2 > > or: > > x == 5 ? puts("one") : puts("two") # Prints two > > thanks. > -- > Posted via http://www.ruby-forum.com/. x = 6 # assignment y = x == 5 ? 0 : 2 # if x equals 5, then assign 0 to y # else assign 2 to y It's the same as y = (x == 5 ? 0 : 2), because in ruby, == takes precedence over = (as does the ternary operation) See http://en.wikipedia.org/wiki/%3F: for more info on ternary op. hth, Todd