LoginSignup
2
2

More than 5 years have passed since last update.

putsがブロックを引数に取る?

Posted at

putsでHashのリテラルを表示させようとしたときに SyntaxError が発生する。

puts {a: :a}

を実行すると、

SyntaxError: unexpected ':', expecting '}'

とエラーが表示されて終了する。
色々調べてみたところ、

puts ({a: :a})

とか、

a = {a: :a}
puts a

であればリテラルが表示される。

と言うことは、puts が{}をブロックとして解釈している??
これは設計通りの動作?でもリファレンスを探しても載っていない。
どなたかご存知の方教えて下さい。

2
2
8

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2