Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby-为什么可以';t和/或语句是否在单独的行上?_Ruby_Scripting - Fatal编程技术网

Ruby-为什么可以';t和/或语句是否在单独的行上?

Ruby-为什么可以';t和/或语句是否在单独的行上?,ruby,scripting,Ruby,Scripting,我正在编写一个非常简单的ruby脚本,并进行了一些检查: if true and true and true then else end 为什么我不能这样格式化呢 if true and true and true then else end 如果我那样做,鲁比会发火。我想这样做,这样我的台词就很长了。我只是简单地将标准作为一个函数来解决这个问题,但是如果我不能把它放到另一行中,我仍然感到非常有限 沃尔特你可以——只要去掉“然后”这个词就行了 /我想:)你可以——只

我正在编写一个非常简单的ruby脚本,并进行了一些检查:

if true and true and true then

else

end
为什么我不能这样格式化呢

if true
   and true
   and true
   then

else

end
如果我那样做,鲁比会发火。我想这样做,这样我的台词就很长了。我只是简单地将标准作为一个函数来解决这个问题,但是如果我不能把它放到另一行中,我仍然感到非常有限

沃尔特

你可以——只要去掉“然后”这个词就行了

/我想:)

你可以——只要去掉“then”就行了


/我想:)

你可以放一个
\
继续这行:

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

这不是最好的样式,但它会起作用。

您可以放置一个
\
来继续这行:

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

这不是最好的风格,但它会起作用。

你也可以这样写:

if true and
  true and
  true
    puts "true"
end

你也可以这样写:

if true and
  true and
  true
    puts "true"
end

括号也可以起作用:

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

正如您已经做过的那样,将标准设置为函数可能是一个更好的解决方案。

括号也可以做到这一点:

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

正如您已经做过的那样,将标准设置为函数可能是一个更好的解决方案。

啊,好吧,我想我已经尝试过了,我肯定不会这么做。我的代码必须看起来有点漂亮,才能在上面打上我的名字。那会有用的。啊,好吧,我想我已经试过了,我肯定不会这么做。我的代码必须看起来有点漂亮,才能在上面打上我的名字。那就行了。