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")