Class: ActiveSupport::OrderedHash
- Inherits:
-
Array
show all
- Defined in:
- lib/active_support/ordered_hash.rb
Overview
Instance Method Summary
collapse
#rand
#in_groups, #in_groups_of, #split
#extract_options!
included, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml
#fifth, #forty_two, #fourth, #from, #second, #third, #to
Instance Method Details
18
19
20
21
|
# File 'lib/active_support/ordered_hash.rb', line 18
def [](key)
pair = assoc(key)
pair ? pair.last : nil
end
|
#[]=(key, value) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# 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
value
end
|
#delete(key) ⇒ Object
23
24
25
26
27
|
# File 'lib/active_support/ordered_hash.rb', line 23
def delete(key)
pair = assoc(key)
pair ? array_index = index(pair) : nil
array_index ? delete_at(array_index).last : nil
end
|
#has_key?(k) ⇒ Boolean
Also known as:
key?, include?, member?
43
44
45
|
# File 'lib/active_support/ordered_hash.rb', line 43
def has_key?(k)
!assoc(k).nil?
end
|
#has_value?(v) ⇒ Boolean
Also known as:
value?
51
52
53
|
# File 'lib/active_support/ordered_hash.rb', line 51
def has_value?(v)
any? { |key, value| value == v }
end
|
29
30
31
|
# File 'lib/active_support/ordered_hash.rb', line 29
def keys
collect { |key, value| key }
end
|
37
38
39
40
41
|
# File 'lib/active_support/ordered_hash.rb', line 37
def to_hash
returning({}) do |hash|
each { |array| hash[array[0]] = array[1] }
end
end
|
33
34
35
|
# File 'lib/active_support/ordered_hash.rb', line 33
def values
collect { |key, value| value }
end
|