Class: Sass::OrderedHash
- Includes:
- Enumerable
- Defined in:
- lib/gems/haml-2.0.4/lib/sass/css.rb
Overview
This class is based on the Ruby 1.9 ordered hashes. It keeps the semantics and most of the efficiency of normal hashes while also keeping track of the order in which elements were set.
Defined Under Namespace
Classes: Node
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each {|[@first.key, @first.value]| ... } ⇒ Object
-
#initialize ⇒ OrderedHash
constructor
A new instance of OrderedHash.
- #initialize_copy(other) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ OrderedHash
Returns a new instance of OrderedHash.
58 59 60 |
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 58 def initialize @hash = {} end |
Instance Method Details
#[](key) ⇒ Object
66 67 68 |
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 66 def [](key) @hash[key] && @hash[key].value end |
#[]=(key, value) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 70 def []=(key, value) node = Node.new(key, value) if old = @hash[key] if old.prev old.prev.next = old.next else # old is @first and @last @first = @last = nil end end if @first.nil? @first = @last = node else node.prev = @last @last.next = node @last = node end @hash[key] = node value end |
#each {|[@first.key, @first.value]| ... } ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 93 def each return unless @first yield [@first.key, @first.value] node = @first yield [node.key, node.value] while node = node.next self end |
#initialize_copy(other) ⇒ Object
62 63 64 |
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 62 def initialize_copy(other) @hash = other.instance_variable_get('@hash').clone end |
#values ⇒ Object
101 102 103 |
# File 'lib/gems/haml-2.0.4/lib/sass/css.rb', line 101 def values self.map { |k, v| v } end |