Class: ReeArray::SplitBy
- Inherits:
-
Object
- Object
- ReeArray::SplitBy
- Includes:
- Ree::FnDSL
- Defined in:
- lib/ree_lib/packages/ree_array/package/ree_array/functions/split_by.rb
Instance Method Summary collapse
Instance Method Details
#call(array, value = nil, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ree_lib/packages/ree_array/package/ree_array/functions/split_by.rb', line 16 def call(array, value = nil, &block) arr = array.dup result = [] if block_given? while (idx = arr.index(&block)) result << arr.shift(idx) arr.shift end else while (idx = arr.index(value)) result << arr.shift(idx) arr.shift end end result << arr end |