Class: Array

Inherits:
Object show all
Defined in:
opal/fron/core_ext/array.rb

Overview

Array extensions

Instance Method Summary collapse

Instance Method Details

#_uniqObject



24
25
26
27
28
29
30
31
32
33
34
# File 'opal/fron/core_ext/array.rb', line 24

def _uniq
  return uniq unless block_given?
  data = uniq
  results = []
  data.reject do |item|
    value = yield item
    next true if results.include? value
    results << value
    false
  end
end

#reverse_each_with_indexObject

Runs through the elements form the back with index

Yield Returns:

  • (*)

    The item and index



7
8
9
10
11
# File 'opal/fron/core_ext/array.rb', line 7

def reverse_each_with_index
  (0...length).reverse_each do |i|
    yield self[i], i
  end
end

#sort_by!Array

Sort by array in place.

Parameters:

  • block (Proc)

    The block

Returns:



18
19
20
21
22
# File 'opal/fron/core_ext/array.rb', line 18

def sort_by!
  sort! do |a, b|
    yield(a) <=> yield(b)
  end
end