On this page
class Bundler::Thor::CoreExt::OrderedHash
Public Class Methods
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 5
def initialize(*args, &block)
super
@keys = []
end
Calls superclass method
Hash::new
Public Instance Methods
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 16
def []=(key, value)
@keys << key unless key?(key)
super
end
Calls superclass method
Hash#[]=
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 83
def clear
super
@keys.clear
self
end
Calls superclass method
Hash#clear
# 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
Calls superclass method
Hash#delete
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 29
def delete_if
super
sync_keys!
self
end
Calls superclass method
Hash#delete_if
# 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
# 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
# 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
# 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
# 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
Calls superclass method
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 117
def inspect
"#<#{self.class} #{super}>"
end
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 41
def keys
@keys.dup
end
# 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
# 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
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 37
def reject(&block)
dup.reject!(&block)
end
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 111
def replace(other)
super
@keys = other.keys
self
end
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 89
def shift
k = @keys.first
v = delete(k)
[k, v]
end
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 123
def sync_keys!
@keys.delete_if { |k| !key?(k) }
end
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 53
def to_a
@keys.map { |key| [key, self[key]] }
end
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 49
def to_hash
self
end
# File lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb, line 45
def values
@keys.map { |key| self[key] }
end
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.