### Home Classes Methods

### In Files

- lib/sass/util/ordered_hash.rb

### Parent

Hash

### Methods

- ::[]
- ::new
- #[]=
- #clear
- #delete
- #delete_if
- #each
- #each_key
- #each_pair
- #each_value
- #initialize_copy
- #inspect
- #invert
- #keys
- #merge
- #merge!
- #reject
- #reject!
- #replace
- #shift
- #to_a
- #to_hash
- #update
- #values

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# OrderedHash

This class was copied from an old version of ActiveSupport.

### Public Class Methods

[](*args) click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 39
    def self.[](*args)
      ordered_hash = new

      if args.length == 1 && args.first.is_a?(Array)
        args.first.each do |key_value_pair|
          next unless key_value_pair.is_a?(Array)
          ordered_hash[key_value_pair[0]] = key_value_pair[1]
        end

        return ordered_hash
      end

      unless args.size.even?
        raise ArgumentError.new("odd number of arguments for Hash")
      end

      args.each_with_index do |val, ind|
        next if ind.odd?
        ordered_hash[val] = args[ind + 1]
      end

      ordered_hash
    end

new(*args) click to toggle source

In MRI the Hash class is core and written in C. In particular, methods are programmed with explicit C function calls and polymorphism is not honored.

For example, []= is crucial in this implementation to maintain the @keys array but hash.c invokes rb_hash_aset() originally. This prevents method reuse through inheritance and forces us to reimplement stuff.

For instance, we cannot use the inherited merge! because albeit the algorithm itself would work, our []= is not being called at all by the C code.

    # File lib/sass/util/ordered_hash.rb, line 34
    def initialize(*args)
      super
      @keys = []
    end

### Public Instance Methods

[]=(key, value) click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 69
    def []=(key, value)
      @keys << key unless has_key?(key)
      super
    end

clear() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 140
    def clear
      super
      @keys.clear
      self
    end

delete(key) click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 74
    def delete(key)
      if has_key? key
        index = @keys.index(key)
        @keys.delete_at index
      end
      super
    end

delete_if() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 82
    def delete_if
      super
      sync_keys!
      self
    end

each() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 126
    def each
      return to_enum(:each) unless block_given?
      @keys.each {|key| yield [key, self[key]]}
      self
    end

each_key() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 114
    def each_key
      return to_enum(:each_key) unless block_given?
      @keys.each {|key| yield key}
      self
    end

each_pair() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 132
    def each_pair
      return to_enum(:each_pair) unless block_given?
      @keys.each {|key| yield key, self[key]}
      self
    end

each_value() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 120
    def each_value
      return to_enum(:each_value) unless block_given?
      @keys.each {|key| yield self[key]}
      self
    end

initialize_copy(other) click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 63
    def initialize_copy(other)
      super
      # make a deep copy of keys
      @keys = other.keys
    end

inspect() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 183
    def inspect
      "#<OrderedHash #{super}>"
    end

invert() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 179
    def invert
      OrderedHash[to_a.map! {|key_value_pair| key_value_pair.reverse}]
    end

keys() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 98
    def keys
      @keys.dup
    end

merge(other_hash) click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 163
    def merge(other_hash)
      if block_given?
        dup.merge!(other_hash) {|k, v1, v2| yield k, v1, v2}
      else
        dup.merge!(other_hash)
      end
    end

merge!(other_hash) click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 152
    def merge!(other_hash)
      if block_given?
        other_hash.each {|k, v| self[k] = key?(k) ? yield(k, self[k], v) : v}
      else
        other_hash.each {|k, v| self[k] = v}
      end
      self
    end

Also aliased as: update
reject() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 94
    def reject
      dup.reject! {|h, k| yield h, k}
    end

reject!() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 88
    def reject!
      super
      sync_keys!
      self
    end

replace(other) click to toggle source

When replacing with another hash, the initial order of our keys must come from the other hash – ordered or not.

    # File lib/sass/util/ordered_hash.rb, line 173
    def replace(other)
      super
      @keys = other.keys
      self
    end

shift() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 146
    def shift
      k = @keys.first
      v = delete(k)
      [k, v]
    end

to_a() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 110
    def to_a
      @keys.map {|key| [key, self[key]]}
    end

to_hash() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 106
    def to_hash
      self
    end

update(other_hash) click to toggle source
Alias for: merge!
values() click to toggle source

    # File lib/sass/util/ordered_hash.rb, line 102
    def values
      @keys.map {|key| self[key]}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.