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?

配列はいらないけど配列の中身は欲しい時

Posted at

答え

splat演算子を使う

## 例1

t, *s = [1,2,3]
puts *s
# 2
# 3

配列ではなく単体の数値が出力される

## 例2

jp = ['japan', '日本']
 country = '日本'
 case country
 # *により配列が展開され、when 'japan', '日本'と書いたのと同じ意味になる
 when *jp
   'こんにちは'
 end
 #=> "こんにちは”

抜粋:
Software Design plusシリーズ プロを目指す人のためのRuby入門[改訂2版] 言語仕様からテスト駆動開発・デバッグ技法まで
伊藤 淳一

引用元

Software Design plusシリーズ プロを目指す人のためのRuby入門[改訂2版] 言語仕様からテスト駆動開発・デバッグ技法まで

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