jRuby / Rails使用AND / OR的if-else的正确语法

时间:2011-12-15 01:43:57

标签: if-statement jruby

对于具有多个约束的IF语句,Ruby的正确语法是什么。

你可以在php中做的例子。

if(($something == $this) AND ($this == $that))

所以我正在寻找该语法的Ruby演绎。我尝试搜索它,但由于它的常用词,并且大多数搜索引擎使用相同的单词作为条件,我的搜索提出了非常小的。

2 个答案:

答案 0 :(得分:2)

你真的尝试过什么吗?

语法离php不远:

if ((2 % 2 == 0) and (3 % 2 == 1))
  puts "2 is even, 3 is not"
end

您应该阅读Ruby's if syntax

答案 1 :(得分:1)

if something == this && this == that

if something == this and this == that

您应be careful使用and