Sha256: db079ff44f7394b36a9055e4ec006460c63e38db998aba9046d52afbf4059084

Contents?: true

Size: 878 Bytes

Versions: 1

Compression:

Stored size: 878 Bytes

Contents

class Array
  # Performs a "deep copy" of this array; that is, returns an Array that is a duplicate of this Array, and whose
  # elements have each, in turn, had #deep_dup or #dup called on them. This should produce an Array whose every
  # element is a copy of the original.
  #
  # This operation is expensive, and should be used sparingly.
  def deep_dup
    self.collect do |ele|
      ele.respond_to?(:deep_dup) ? ele.deep_dup : ele.dup?
    end
  end

  # Modulus operator: returns an array consisting only of those elements that are shared by both this array and
  # the arr object. If arr is not an array, then only elements equal to arr itself are returned.
  #
  # Examples:
  #   [1, 2, 3] % [1, 2]   # => [1, 2]
  #   [1, 2, 3] % 2        # => [2]
  #
  def %(arr)
    select { |i| arr.kind_of?(Array) ? arr.include?(i) : arr == i }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sc-core-ext-1.1.1 lib/sc-core-ext/array.rb