Class: Array

Inherits:
Object show all
Extended by:
Filigree::Destructurable
Defined in:
lib/filigree/array.rb,
lib/filigree/match.rb

Overview

Standard Library Deconstructors #

Instance Method Summary collapse

Methods included from Filigree::Destructurable

call

Instance Method Details

#aliased_mapObject



19
# File 'lib/filigree/array.rb', line 19

alias :aliased_map :map

#destructure(num_elems) ⇒ Array<Object>

Destructuring for the array class. If the array is being matched against two patterns the destructuring of the array will be the first element and then an array containing the rest of the values. If there are three patterns the destructuring of the array will be the first and second elements, and then an array containing the remainder of the values.

Parameters:

  • num_elems (Fixnum)

    Number of sub-pattern elements

Returns:



487
488
489
# File 'lib/filigree/match.rb', line 487

def destructure(num_elems)
	[*self.first(num_elems - 1), self[(num_elems - 1)..-1]]
end

#map(method = nil, &block) ⇒ Array<Object>

Map now takes an optional symbol argument. If a symbol is provided the specified method is invoked on each of the objects in the array.

Parameters:

  • method (Symbol) (defaults to: nil)

    Method to be invoked on the array elements.

  • block (Proc)

    Normal Array#each block.

Returns:



28
29
30
31
32
33
34
# File 'lib/filigree/array.rb', line 28

def map(method = nil, &block)
	if method
		self.aliased_map { |obj| obj.send(method) }
	else
		self.aliased_map(&block)
	end
end