LoginSignup
3
1

More than 5 years have passed since last update.

Rubyでの配列の数、要素の長さの出し方の3つめ?

Last updated at Posted at 2018-04-11

最近,paizaのdを全盗.

rubyでのarrayの要素数はlength,size以外だとcountもあった.

count (Array) - Rubyリファレンス

countメソッドは、配列の中で引数objと同じ要素の数を返します。引数を省略したときは、単純に要素の数を返します。

numbers = [1, 2, 5, 5, 1, 3, 1, 2, 4, 3]
puts numbers.count(1)
puts numbers.count
3
10
3
1
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
3
1