Shuaib Zahda wrote: > Hi all > > in my program I am using a lot of true false conditions. So, I want to > shorten my code by using the conditional operator ? : but when I use the > word return it gives an error which i do not really know why? > > e.g. x == 5 ? return true : return false > SyntaxError: compile error > (irb):19: syntax error, unexpected kTRUE > > but if i do not use return it works > > x == 5 ? true : false The ternary operator ? : evaluates to a value, so it expects values (or expressions evaluating to values, but not statements as in your example) after ? and : . You would also not write x = return 5 because during an assignment, Ruby expects a value on the right side of the equation mark. Cheers, Peter ___ http://www.rubyrailways.com http://scrubyt.org