Class: ActiveSupport::OrderedHash
- Inherits:
-
Array
show all
- Defined in:
- lib/active_support/ordered_hash.rb
Overview
Instance Method Summary
collapse
#rand
#in_groups_of, #split
#extract_options!
included, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml
#from, #to
Instance Method Details
17
18
19
20
|
# File 'lib/active_support/ordered_hash.rb', line 17
def [](key)
pair = assoc(key)
pair ? pair.last : nil
end
|
#[]=(key, value) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/active_support/ordered_hash.rb', line 8
def []=(key, value)
if pair = assoc(key)
pair.pop
pair << value
else
self << [key, value]
end
end
|
#delete(key) ⇒ Object
22
23
24
25
26
|
# File 'lib/active_support/ordered_hash.rb', line 22
def delete(key)
pair = assoc(key)
pair ? array_index = index(pair) : nil
array_index ? delete_at(array_index).last : nil
end
|
28
29
30
|
# File 'lib/active_support/ordered_hash.rb', line 28
def keys
collect { |key, value| key }
end
|
36
37
38
39
40
|
# File 'lib/active_support/ordered_hash.rb', line 36
def to_hash
returning({}) do |hash|
each { |array| hash[array[0]] = array[1] }
end
end
|
32
33
34
|
# File 'lib/active_support/ordered_hash.rb', line 32
def values
collect { |key, value| value }
end
|