Sha256: c62de8f4770200a14532372908f8fbaa233dde60a4865637a14675b409236c7c

Contents?: true

Size: 860 Bytes

Versions: 9

Compression:

Stored size: 860 Bytes

Contents

###
### $Rev$
### 0.7.2
### $COPYRIGHT$
###

module Kwalify

  module Util

    class OrderedHash < Hash

      def initialize(*args, &block)
        super
        @_keys = []
      end

      alias __set__ []=

      def put(key, val)
        @_keys << key unless self.key?(key)
        __set__(key, val)
      end

      def add(key, val)
        @_keys.delete_at(@_keys.index(key)) if self.key?(key)
        @_keys << key
        __set__(key, val)
      end

      alias []= put
      #alias []= add

      def keys
        return @_keys.dup
      end

      def values
        return @_keys.collect {|key| self[key] }
      end

      def delete(key)
        @_keys.delete_at(@_keys.index(key)) if self.key?(key)
        super
      end

      def each
        @_keys.each do |key|
          yield key, self[key]
        end
      end

    end

  end

end

Version data entries

9 entries across 7 versions & 4 rubygems

Version Path
dc-kwalify-1.0.0 lib/kwalify/util/ordered-hash.rb
dc-kwalify-0.7.2 lib/kwalify/util/ordered-hash.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb
tpkg-2.3.5 lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb
tpkg-2.3.4 lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb
kwalify-0.7.2 lib/kwalify/util/ordered-hash.rb