LoginSignup
0
2

More than 5 years have passed since last update.

本日 Ruby でハマったカンマの罠

Posted at

複数行で代入しているシチュエーションがあって、うっかりお尻のカンマを取り忘れてしまいました。

さて、この場合 id には何が入るのでしょうか?

id = 1,
name = "eccyan"

.
.
.
.
.


さて、上記の処理ですが、お尻のカンマが処理を継続させて以下の式の様に評価されます。

 id = 1, name = "eccyan" 
 id = [1, name = "eccyan"] 

name = "eccyan" が評価され

pry(main)> id = 1,
pry(main)* name = "eccyan"
=> [1, "eccyan"]

.
.
.
.
.

(⸅̥᷇˲̎ͨ⸅̥᷆̾ ˒͋) < おいカツオ!

別に何も意図はありません。どうもありがとうございました。

0
2
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
0
2