Parent

Class/Module Index [+]

Quicksearch

Insertion

The Insertion class inserts a value before or after another value in a list.

@example

Insertion.new([1, 2, 3], 4).before(3) # => [1, 2, 4, 3]

Public Class Methods

new(list, value) click to toggle source

Creates an insertion object on a list with a value to be inserted. To finalize the insertion, call {before} or {after} on the object.

@param [Array] list the list to perform the insertion on @param [Object] value the value to insert

# File lib/yard/core_ext/insertion.rb, line 13
def initialize(list, value) @list, @values = list, (Array === value ? value : [value]) end

Public Instance Methods

after(val, recursive = false) click to toggle source

Inserts the value after val.

@example If subsections are ignored

Insertion.new([1, [2], 3], :X).after(1) # => [1, [2], :X, 3]

@param [Object] val the object the value will be inserted after @param [Boolean] recursive look inside sublists

# File lib/yard/core_ext/insertion.rb, line 26
def after(val, recursive = false) insertion(val, 1, recursive) end
after_any(val) click to toggle source

Alias for {after} with recursive set to true @since 0.6.0

# File lib/yard/core_ext/insertion.rb, line 34
def after_any(val) insertion(val, 1, true) end
before(val, recursive = false) click to toggle source

Inserts the value before val @param [Object] val the object the value will be inserted before @param [Boolean] recursive look inside sublists

# File lib/yard/core_ext/insertion.rb, line 18
def before(val, recursive = false) insertion(val, 0, recursive) end
before_any(val) click to toggle source

Alias for {before} with recursive set to true @since 0.6.0

# File lib/yard/core_ext/insertion.rb, line 30
def before_any(val) insertion(val, 0, true) end

[Validate]

Generated with the Darkfish Rdoc Generator 2.