Class: ActiveSupport::OrderedHash
- Inherits:
-
Hash
show all
- Defined in:
- lib/active_support/ordered_hash.rb
Overview
Constant Summary
CoreExtensions::Hash::Conversions::XML_FORMATTING, CoreExtensions::Hash::Conversions::XML_PARSING, CoreExtensions::Hash::Conversions::XML_TYPE_NAMES
Instance Method Summary
collapse
Methods inherited from Hash
#to_json
#except, #except!
#slice, #slice!
#diff
included, #rename_key, #to_query, #to_xml
#reverse_merge, #reverse_merge!
#deep_merge, #deep_merge!
#with_indifferent_access
#assert_valid_keys, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!
Constructor Details
#initialize(*args, &block) ⇒ OrderedHash
Returns a new instance of OrderedHash.
8
9
10
11
|
# File 'lib/active_support/ordered_hash.rb', line 8
def initialize(*args, &block)
super
@keys = []
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
19
20
21
22
|
# File 'lib/active_support/ordered_hash.rb', line 19
def []=(key, value)
@keys << key if !has_key?(key)
super
end
|
74
75
76
77
78
|
# File 'lib/active_support/ordered_hash.rb', line 74
def clear
super
@keys.clear
self
end
|
#delete(key) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/active_support/ordered_hash.rb', line 24
def delete(key)
if has_key? key
index = @keys.index(key)
@keys.delete_at index
end
super
end
|
#delete_if ⇒ Object
32
33
34
35
36
|
# File 'lib/active_support/ordered_hash.rb', line 32
def delete_if
super
sync_keys!
self
end
|
#each ⇒ Object
Also known as:
each_pair
68
69
70
|
# File 'lib/active_support/ordered_hash.rb', line 68
def each
@keys.each {|key| yield [key, self[key]]}
end
|
60
61
62
|
# File 'lib/active_support/ordered_hash.rb', line 60
def each_key
@keys.each { |key| yield key }
end
|
#each_value ⇒ Object
64
65
66
|
# File 'lib/active_support/ordered_hash.rb', line 64
def each_value
@keys.each { |key| yield self[key]}
end
|
#initialize_copy(other) ⇒ Object
13
14
15
16
17
|
# File 'lib/active_support/ordered_hash.rb', line 13
def initialize_copy(other)
super
@keys = other.keys
end
|
95
96
97
|
# File 'lib/active_support/ordered_hash.rb', line 95
def inspect
"#<OrderedHash #{super}>"
end
|
48
49
50
|
# File 'lib/active_support/ordered_hash.rb', line 48
def keys
@keys.dup
end
|
#merge(other_hash) ⇒ Object
91
92
93
|
# File 'lib/active_support/ordered_hash.rb', line 91
def merge(other_hash)
dup.merge!(other_hash)
end
|
#merge!(other_hash) ⇒ Object
86
87
88
89
|
# File 'lib/active_support/ordered_hash.rb', line 86
def merge!(other_hash)
other_hash.each {|k,v| self[k] = v }
self
end
|
#reject(&block) ⇒ Object
44
45
46
|
# File 'lib/active_support/ordered_hash.rb', line 44
def reject(&block)
dup.reject!(&block)
end
|
38
39
40
41
42
|
# File 'lib/active_support/ordered_hash.rb', line 38
def reject!
super
sync_keys!
self
end
|
80
81
82
83
84
|
# File 'lib/active_support/ordered_hash.rb', line 80
def shift
k = @keys.first
v = delete(k)
[k, v]
end
|
56
57
58
|
# File 'lib/active_support/ordered_hash.rb', line 56
def to_hash
self
end
|
52
53
54
|
# File 'lib/active_support/ordered_hash.rb', line 52
def values
@keys.collect { |key| self[key] }
end
|