【发布时间】:2012-03-08 19:45:54
【问题描述】:
我很困惑 Ruby 1.9(JRuby 1.6.6 (RUBY_VERSION == "1.9.2") 和 Ruby 1.9.3-p125)给出了puts(true and false) 的语法错误。
我不知道为什么 - 这里有什么问题?我将如何正确编写那段代码? puts(true && false) 有效,但有 and 的解决方案吗?
irb 会话示例:
1.9.3p125 :001 > puts(true and false)
SyntaxError: (irb):1: syntax error, unexpected keyword_and, expecting ')'
puts(true and false)
^
from /home/fr/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'
1.9.3p125 :002 > puts(true && false)
false
=> nil
感谢 Mladen Jabnović 简化了示例。旧示例是f(true and f(false))。
【问题讨论】:
-
简化的例子是
puts(true and false) -
感谢@Thilo 和@Mladen。我知道运算符优先级,但对我来说这并不能解释这种现象。感谢
puts的示例,这要简单得多。
标签: ruby