0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Ruby】hoge = piyo = ‘fuga’ の意味

Last updated at Posted at 2021-06-18

参画中のプロジェクトのソースコードを読んでいるときに、以下のような記述があった。

hoge = piyo = 'fuga'

試してみる

[1] pry(main)> hoge = piyo = 'fuga'
=> "fuga"
[2] pry(main)> hoge
=> "fuga"
[3] pry(main)> piyo
=> "fuga"

解説

~~多重代入という。~~2つ以上の変数に同じ値を代入できるようだ。

hoge = piyo = 'fuga'

したがって、上記式の意味は
変数hoge と 変数piyo に 文字列‘fuga’ を代入する
となる。

ただし、特別な理由がなければ使わないほうが良さそう。

0
0
2

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?