Module: Enumerable

Included in:
InBetweenEnum, Wood::Nodes::CodeBlock
Defined in:
lib/core_ext/enumerable.rb

Defined Under Namespace

Classes: InBetweenEnum

Instance Method Summary collapse

Instance Method Details

#in_between(&block) ⇒ InBetweenEnum

Creates a InBetweenEnum for iteration while calling ‘block` in between.

Parameters:

  • block (Proc, #call)

    Block to be called in between each element

Returns:

  • (InBetweenEnum)

    Enumerable like object for iterating over elements in ‘self` while calling `block` in between.



28
29
30
# File 'lib/core_ext/enumerable.rb', line 28

def in_between(&block)
  InBetweenEnum.new(self, block)
end

#map_with_indexArray

Same as #map but passing along the index with each element to a given block.

Examples:

["a","b","c"].map_with_index do |x, i|
  x + (i * 2).to_s
end
=> ["a0", "b2", "c4"]

Returns:

  • (Array)

    Mapped items based on block given.



40
41
42
43
44
45
46
# File 'lib/core_ext/enumerable.rb', line 40

def map_with_index
  arr = []
  each_with_index do |x, i|
    arr << yield(x, i)
  end
  arr
end