2
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]配列の要素を結合して一つの文字列にするjoinメソッドについて

Posted at

はじめに

joinメソッドについて学習したのでメモとして残しておきます。

使い方

joinメソッドは非破壊的メソッドです。
引数がない場合は配列の要素を結合して、一つの文字列にします。
また引数を取った場合は引数を区切り文字として使います。

使用例

array1 = [1,2,3]
array1 = array.join
p array1
=> "123"

array2 = [1,2,3]
array2 = array2.join("-")
p array2
=> "1-2-3"

array3 = [1,2,3]
array3 = array3.join(" ")
p array3
=> "1 2 3"

##参考
https://docs.ruby-lang.org/ja/latest/method/Array/i/join.html

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