Sha256: 570d7e1ce33c987f5b14a76abc73ae7bd242a680806e78537caec5c843827e40

Contents?: true

Size: 537 Bytes

Versions: 5

Compression:

Stored size: 537 Bytes

Contents

class OrderedOptions < Array #:nodoc:
  def []=(key, value)
    key = key.to_sym
    
    if pair = find_pair(key)
      pair.pop
      pair << value
    else
      self << [key, value]
    end
  end
  
  def [](key)
    pair = find_pair(key.to_sym)
    pair ? pair.last : nil
  end

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

  private
    def find_pair(key)
      self.each { |i| return i if i.first == key }
      return false
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activesupport-1.2.1 lib/active_support/ordered_options.rb
activesupport-1.2.2 lib/active_support/ordered_options.rb
activesupport-1.2.5 lib/active_support/ordered_options.rb
activesupport-1.2.4 lib/active_support/ordered_options.rb
activesupport-1.2.3 lib/active_support/ordered_options.rb