Sha256: baec247f8c96fe29a11567354f593de136006f7c95aba241f71d13be78cdc7f9

Contents?: true

Size: 929 Bytes

Versions: 19

Compression:

Stored size: 929 Bytes

Contents

# OrderedHash is namespaced to prevent conflicts with other implementations
module ActiveSupport
  # Hash is ordered in Ruby 1.9!
  if RUBY_VERSION >= '1.9'
    OrderedHash = ::Hash
  else
    class OrderedHash < Array #:nodoc:
      def []=(key, value)
        if pair = assoc(key)
          pair.pop
          pair << value
        else
          self << [key, value]
        end
      end

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

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

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

class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
  def []=(key, value)
    super(key.to_sym, value)
  end

  def [](key)
    super(key.to_sym)
  end

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

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
activesupport-2.0.0 lib/active_support/ordered_options.rb
activesupport-2.0.1 lib/active_support/ordered_options.rb
activesupport-2.0.2 lib/active_support/ordered_options.rb
radiant-0.6.5.1 vendor/rails/activesupport/lib/active_support/ordered_options.rb
radiant-0.6.5 vendor/rails/activesupport/lib/active_support/ordered_options.rb
radiant-0.6.6 vendor/rails/activesupport/lib/active_support/ordered_options.rb
radiant-0.6.7 vendor/rails/activesupport/lib/active_support/ordered_options.rb
radiant-0.6.9 vendor/rails/activesupport/lib/active_support/ordered_options.rb
radiant-0.6.8 vendor/rails/activesupport/lib/active_support/ordered_options.rb
spree-0.0.9 vendor/rails/activesupport/lib/active_support/ordered_options.rb
spree-0.2.0 vendor/rails/activesupport/lib/active_support/ordered_options.rb
swivel-0.0.150 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb
swivel-0.0.149 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb
swivel-0.0.152 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb
swivel-0.0.157 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb
swivel-0.0.160 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb
swivel-0.0.155 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb
swivel-0.0.156 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb
swivel-0.0.175 vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb