0
1

More than 3 years have passed since last update.

Ruby技術者認定試験

Posted at

Ruby技術者認定試験の勉強をする中で学んだことを記録に残すもの。

zip

Enumerableモジュールで提供されるメソッド。Arrayクラスは、Enumerableモジュールをインクルードしている。

a = [1,2,3]
b = [4,5,6]
a.zip(b) #=>[[1, 4], [2, 5], [3, 6]]

[1,2,3].zip([4,5,6])
#=>=> [[1, 4], [2, 5], [3, 6]]

範囲演算子(../...)

(5..10).to_a   #=>[5,6,7,8,9,10]
(5...10).to_a  #=>[5,6,7,8,9]

select/find_all

Enumerableモジュールで提供されるメソッド。Arrayクラスは、Enumerableモジュールをインクルードしている。
各要素に対してブロックを実行し、結果が真となる要素を探して(find/select)配列にして返す。

numbers = [1,2,3,4,5]
numbers.select{|n|.even?}   #=> [2, 4]
numbers.find_all{|n|.even?} #=> [2, 4]
0
1
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
1