Class: Racket::Misc::OrderedHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/racket/misc/orderedhash.rb

Overview

members around

Instance Method Summary collapse

Constructor Details

#initializeOrderedHash

Returns a new instance of OrderedHash.



35
36
37
# File 'lib/racket/misc/orderedhash.rb', line 35

def initialize
  @keys = []
end

Instance Method Details

#[]=(key, val) ⇒ Object



39
40
41
42
# File 'lib/racket/misc/orderedhash.rb', line 39

def []=(key, val)
  @keys << key unless (self[key])
  super
end

#delete(key) ⇒ Object



44
45
46
47
# File 'lib/racket/misc/orderedhash.rb', line 44

def delete(key)
  @keys.delete(key)
  super
end

#eachObject



49
50
51
# File 'lib/racket/misc/orderedhash.rb', line 49

def each
  @keys.each { |k| yield k, self[k] }
end

#each_keyObject



53
54
55
# File 'lib/racket/misc/orderedhash.rb', line 53

def each_key
  @keys.each { |k| yield k }
end

#each_valueObject



57
58
59
# File 'lib/racket/misc/orderedhash.rb', line 57

def each_value
  @keys.each { |k| yield self[k] }
end