tags:

views:

70

answers:

4

Hi all,

I am writing a very simple ruby script and has a few checks:

if true and true and true then

else

end

Why can I not format it this way

if true
   and true
   and true
   then

else

end

Ruby blows up if I do it that way. I want do do it that way so my lines are crazy long. I simply made the criteria a function so that solves the problem, but I still feel very limited if I can't put that onto a separate line.

Walter

A: 

You can -- just drop the 'then'.

/I think :)

Joe
+1  A: 

You can put a \ to continue the line:

if true \
   and true \
   and true
   puts "true!"
end

It's not the best style, but it'll work.

mipadi
+3  A: 

You could also write it:

if true and
  true and
  true
    puts "true"
end
Mark
Ah okay, I thought I had tried that, I definitely ain't doing the \. My code has to look somewhat pretty for me to brand my name on it. That'll work.
+1  A: 

Parentheses will do the trick as well:

if(true
   and true
   and true)
  puts "true!"
end

Making the criteria a function, as you already did, is probably a superior solution.

Wayne Conrad