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

发布于 12-21 10:11 字数 212 浏览 2 评论 0原文

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

php 中的示例你可以这样做。

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

所以我正在寻找该语法的 Ruby 版本。我尝试搜索它,但由于它是常用词,并且大多数搜索引擎使用相同的词作为条件,所以我的搜索结果非常少。

What is the proper syntax with Ruby for an IF statement that has multiple constraints.

example in php you could do.

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

So I am looking for the Ruby rendition of that syntax. I try to search for it, but since its common words, and most search engines use the same words for conditionals my searches come up with very litte.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情深如许2024-12-28 10:11:40

你真的尝试过什么吗?

语法与 php 并没有那么远:

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

您可能应该阅读 Ruby 的 if 语法

Have you actually tried anything?

The syntax isn't that far from php:

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

You should probably read up on Ruby's if syntax

念三年u2024-12-28 10:11:40
if something == this && this == that

或者

if something == this and this == that

您应该小心使用 不过。

if something == this && this == that

or

if something == this and this == that

You should be careful using and though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文