Class: Rails::OrderedOptions

Inherits:
Array
  • Object
show all
Defined in:
lib/initializer.rb

Overview

Needs to be duplicated from Active Support since its needed before Active Support is available. Here both Options and Hash are namespaced to prevent conflicts with other implementations AND with the classes residing in ActiveSupport.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



713
714
715
716
717
718
719
# File 'lib/initializer.rb', line 713

def method_missing(name, *args)
  if name.to_s =~ /(.*)=$/
    self[$1.to_sym] = args.first
  else
    self[name]
  end
end

Instance Method Details

#[](key) ⇒ Object



708
709
710
711
# File 'lib/initializer.rb', line 708

def [](key)
  pair = find_pair(key.to_sym)
  pair ? pair.last : nil
end

#[]=(key, value) ⇒ Object

:nodoc:



697
698
699
700
701
702
703
704
705
706
# File 'lib/initializer.rb', line 697

def []=(key, value)
  key = key.to_sym

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