class Bundler::Thor::CoreExt::OrderedHash

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method Hash::new
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 5
def initialize(*args, &block)
  super
  @keys = []
end

Public Instance Methods

[]=(key, value) click to toggle source
Calls superclass method Hash#[]=
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 16
def []=(key, value)
  @keys << key unless key?(key)
  super
end
clear() click to toggle source
Calls superclass method Hash#clear
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 83
def clear
  super
  @keys.clear
  self
end
delete(key) click to toggle source
Calls superclass method Hash#delete
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 21
def delete(key)
  if key? key
    index = @keys.index(key)
    @keys.delete_at index
  end
  super
end
delete_if() click to toggle source
Calls superclass method Hash#delete_if
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 29
def delete_if
  super
  sync_keys!
  self
end
each() { |key, self| ... } click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 69
def each
  return to_enum(:each) unless block_given?
  @keys.each { |key| yield([key, self[key]]) }
  self
end
each_key() { |key| ... } click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 57
def each_key
  return to_enum(:each_key) unless block_given?
  @keys.each { |key| yield(key) }
  self
end
each_pair() { |key, self| ... } click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 75
def each_pair
  return to_enum(:each_pair) unless block_given?
  @keys.each { |key| yield(key, self[key]) }
  self
end
each_value() { |self| ... } click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 63
def each_value
  return to_enum(:each_value) unless block_given?
  @keys.each { |key| yield(self[key]) }
  self
end
initialize_copy(other) click to toggle source
Calls superclass method Hash#initialize_copy
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 10
def initialize_copy(other)
  super
  # make a deep copy of keys
  @keys = other.keys
end
inspect() click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 117
def inspect
  "#<#{self.class} #{super}>"
end
keys() click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 41
def keys
  @keys.dup
end
merge(other_hash, &block) click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 106
def merge(other_hash, &block)
  dup.merge!(other_hash, &block)
end
merge!(other_hash) { |k, self, v| ... } click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 95
def merge!(other_hash)
  if block_given?
    other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
  else
    other_hash.each { |k, v| self[k] = v }
  end
  self
end
reject(&block) click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 37
def reject(&block)
  dup.reject!(&block)
end
replace(other) click to toggle source

When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.

Calls superclass method Hash#replace
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 111
def replace(other)
  super
  @keys = other.keys
  self
end
shift() click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 89
def shift
  k = @keys.first
  v = delete(k)
  [k, v]
end
sync_keys!() click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 123
def sync_keys!
  @keys.delete_if { |k| !key?(k) }
end
to_a() click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 53
def to_a
  @keys.map { |key| [key, self[key]] }
end
to_hash() click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 49
def to_hash
  self
end
values() click to toggle source
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 45
def values
  @keys.map { |key| self[key] }
end