Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Enumerable | drop_while

概要

Enumerable#drop_while

詳細

Enumerable#drop_while ブロックに指定した条件に対してはじめて偽を返却する要素以降を配列として返却する

サンプル

コード
# encoding: utf-8
require "pp"

list = []
10.times {|i|list << i + 1}

p list
list = list.drop_while {|i|i < 4}
p list
list = list.drop_while {|i|i < 6}
p list
list = list.drop_while {|i|i < 100}
p list
出力
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[4, 5, 6, 7, 8, 9, 10]
[6, 7, 8, 9, 10]
[]