Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Enumerable drop_while() function

  • Last Updated : 05 Dec, 2019

The drop_while() of enumerable is an inbuilt method in Ruby returns an array containing the rest elements after dropping elements up to, but not including, the first element for which the block returns nil or false. In case no block is given it returns the enumerator instead.

Syntax: enu.drop_while { |obj| block }

Parameters: The function takes the block which is used to check the condition.

Return Value: It returns an array of rest elements.

Example 1:






# Ruby program for drop_while method in Enumerable
  
# Initialize
enu = (1..50)
  
# returns rest elements
enu.drop_while {|obj| obj < 48}

Output:

[48, 49, 50]

Example 2:




# Ruby program for drop_while method in Enumerable
  
# Initialize
enu = [7, 14, 10, 21]
  
# returns rest elements
enu.drop_while {|obj| obj % 7 == 0}

Output:

[10, 21]
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!