Array#drop_while
arr.drop_while { |element| block } -> array Returns:
Array · Updated March 13, 2026 · Array Methods arrays elements slicing enumerable
drop_while skips elements from the beginning of an array while the block returns truthy, then returns the rest.
Syntax
arr.drop_while { |element| block }
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
block | Proc | Required | A block that evaluates each element. Returns truthy to skip, falsy to keep. |
Examples
Basic usage
scores = [0, 0, 0, 75, 82, 91, 100]
# Drop leading zeros
scores.drop_while { |s| s == 0 }
# => [75, 82, 91, 100]
# Drop until condition changes
data = [1, 2, 3, 4, 5, 1, 2, 3]
data.drop_while { |n| n < 4 }
# => [4, 5, 1, 2, 3]
With empty arrays
empty = []
empty.drop_while { |x| x }
# => []
Processing sorted data
temperatures = [15, 18, 22, 25, 28, 30, 29, 27, 24, 20]
# Get remaining after cold days
warm_days = temperatures.drop_while { |t| t < 25 }
# => [25, 28, 30, 29, 27, 24, 20]
Skipping blank lines
content = ["", "", "first", "second", ""]
non_empty = content.drop_while(&:empty?)
# => ["first", "second", ""]
Splitting arrays at a condition
scores = [45, 55, 65, 75, 85, 95]
passing = scores.take_while { |s| s < 70 }
failing_remaining = scores.drop_while { |s| s < 70 }
# => passing: [45, 55, 65]
# => failing_remaining: [75, 85, 95]