Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
puts bool ? "true" : "false"
是正确的,但是
bool ? puts "true" : puts "false"
不是。有人可以向我解释这是为什么吗?
边注:
bool ? ( puts "true" ) : ( puts "false" )
工作正常。
当您不在方法调用上加上括号时,Ruby 假定您希望行尾的所有内容都作为参数。也就是说,这些调用是等价的(并且无效的):
bool ? puts "true" : puts "false" bool ? puts("true" : puts "false")