Sha256: f68d4711faea4fa08481e4041083dc75eafebcab72c0cd448f38be127bf8926a

Contents?: true

Size: 812 Bytes

Versions: 2

Compression:

Stored size: 812 Bytes

Contents

module Ykutils
  class Hasharray < Hash
    def initialize(*args)
      super(*args)
      @ary = super.keys
      #    @ary ||= []
      @ary ||= []
    end

    def []=(key, value)
      super(key, value)
      @ary << key unless @ary.index(key)
    end

    def each(&block)
      @ary.each do |it|
        block.call(it, self[it])
      end
    end

    def keys
      @ary
    end

    def values
      @ary.collect { |it| self[it] }
    end

    def clear
      super
      @ary = []
    end

    def replace(*args)
      super(*args)
      @ary = super.keys
      @replace ||= []
    end

    def delete(ind, &block)
      @ary.delete(ind)

      super
    end

    def delete_if(&block)
      @ary.each do |it|
        @ary.delete(it) if block.call(it, self[it])
      end

      super
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ykutils-0.1.10 lib/ykutils/hasharray.rb
ykutils-0.1.8 lib/ykutils/hasharray.rb