LoginSignup
1
1

More than 5 years have passed since last update.

1.8.7 では some_method(a, b, c,) と書けない

Posted at

メソッドの仮引数のリストの最後に , を付けることができるのは 1.9.x からです。
1.8.7 と 1.9.x を行ったり来たりしているとたまに引っかかりますね。

1.8.7
[1] pry(main)> p RUBY_VERSION
"1.8.7"
=> nil
[2] pry(main)> p(1, 2, 3,)
SyntaxError: unexpected ')'
1.9.3
[1] pry(main)> p RUBY_VERSION
"1.9.3"
=> "1.9.3"
[2] pry(main)> p(1, 2, 3,)
1
2
3
=> [1, 2, 3]

ちなみに、Hash の最後の要素の後ろの , は 1.8.7 でも付けられます。

1.8.7
[3] pry(main)> { :foo => 42, :bar => 3, }
=> {:bar=>3, :foo=>42}

(あまり関係ないけど、この記事書いてて 1.9.3 では Kernel.#p の返り値が nil じゃないのを初めて知った……)

1
1
0

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
1
1