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 5 years have passed since last update.

[ruby] 戻り値が配列の場合の挙動

Last updated at Posted at 2019-03-03

背景

戻り値が配列の場合、その取得部分ではどのように挙動するのか。
とても単純で基礎的なことですが、「あれ、実際にどう挙動するんだろう」と一瞬わからなくなったので、覚書として残しておく。

サンプルコード

test.rb
def test
  [1, 2, 3]
end

a, b, c = test

d = test

puts "a = #{a}"
puts "b = #{b}"
puts "c = #{c}"
puts "d = #{d}"

実行結果

a = 1
b = 2
c = 3
d = [1, 2, 3]
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?