Class: ActiveSupport::OrderedHash

Inherits:
Array show all
Defined in:
lib/active_support/ordered_options.rb

Overview

:nodoc:

Direct Known Subclasses

OrderedOptions

Instance Method Summary collapse

Methods included from CoreExtensions::Array::RandomAccess

#rand

Methods included from CoreExtensions::Array::Grouping

#in_groups_of, #split

Methods included from CoreExtensions::Array::ExtractOptions

#extract_options!

Methods included from CoreExtensions::Array::Conversions

included, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml

Methods included from CoreExtensions::Array::Access

#from, #to

Instance Method Details

#[](key) ⇒ Object



17
18
19
20
# File 'lib/active_support/ordered_options.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_options.rb', line 8

def []=(key, value)
  if pair = assoc(key)
    pair.pop
    pair << value
  else
    self << [key, value]
  end
end

#keysObject



22
23
24
# File 'lib/active_support/ordered_options.rb', line 22

def keys
  collect { |key, value| key }
end

#to_hashObject



30
31
32
33
34
# File 'lib/active_support/ordered_options.rb', line 30

def to_hash
  returning({}) do |hash|
    each { |array| hash[array[0]] = array[1] }
  end
end

#valuesObject



26
27
28
# File 'lib/active_support/ordered_options.rb', line 26

def values
  collect { |key, value| value }
end