Class: Pipeable::Steps::Insert

Inherits:
Abstract
  • Object
show all
Defined in:
lib/pipeable/steps/insert.rb

Overview

Inserts elements before or after an object.

Constant Summary collapse

LAST =
-1

Instance Method Summary collapse

Methods included from Composable

#<<, #>>

Constructor Details

#initialize(at: LAST) ⇒ Insert

Returns a new instance of Insert.



9
10
11
12
# File 'lib/pipeable/steps/insert.rb', line 9

def initialize(*, at: LAST)
  super(*)
  @at = at
end

Instance Method Details

#call(result) ⇒ Object



14
15
16
17
18
19
# File 'lib/pipeable/steps/insert.rb', line 14

def call result
  result.fmap do |object|
    cast = object.is_a?(Array) ? object : [object]
    cast.insert(at, *base_positionals)
  end
end