Sha256: 8ecd9a41c5cb6f72704ca2d702a0ba7ac5b6cff592ec9108384a5bb57ad5bba0

Contents?: true

Size: 994 Bytes

Versions: 5

Compression:

Stored size: 994 Bytes

Contents

module Hike
  class NormalizedArray < Array
    def initialize
      super()
    end

    def []=(*args)
      value = args.pop

      if value.respond_to?(:to_ary)
        value = normalize_elements(value)
      else
        value = normalize_element(value)
      end

      super *args.concat([value])
    end

    def <<(element)
      super normalize_element(element)
    end

    def collect!
      super do |element|
        result = yield element
        normalize_element(result)
      end
    end

    alias_method :map!, :collect!

    def insert(index, *elements)
      super index, *normalize_elements(elements)
    end

    def push(*elements)
      super *normalize_elements(elements)
    end

    def replace(elements)
      super normalize_elements(elements)
    end

    def unshift(*elements)
      super *normalize_elements(elements)
    end

    def normalize_elements(elements)
      elements.map do |element|
        normalize_element(element)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hike-0.1.4 lib/hike/normalized_array.rb
hike-0.1.3 lib/hike/normalized_array.rb
hike-0.1.2 lib/hike/normalized_array.rb
hike-0.1.1 lib/hike/normalized_array.rb
hike-0.1.0 lib/hike/normalized_array.rb