Class: Dictionary

Inherits
Hashery::Dictionary
  • Object
show all
Defined in
lib/kyanite/dictionary.rb

Dictionary Additions

Kyanite definitions

Dictionary, Hash

Kyanite tests and examples

TestKyaniteDictionary

Base class

Hashery::Dictionary (A Dictionary is a Hash that preserves order.)

Usage

require 'kyanite/dictionary'

Instance Method Summary (collapse)

Instance Method Details

- (Object) -(other)



32
33
34
# File 'lib/kyanite/dictionary.rb', line 32

def -(other)
  (self.to_a - other.to_a).to_dictionary
end

- (Object) each_with_index



47
48
49
50
# File 'lib/kyanite/dictionary.rb', line 47

def each_with_index
  order.each_with_index { |k,i| yield( k, @hash[k], i ) }
  self
end

- (Object) fetch_by_index(index)



20
21
22
# File 'lib/kyanite/dictionary.rb', line 20

def fetch_by_index(index)
  @hash[order[index]]
end

- (Object) first_key



24
25
26
# File 'lib/kyanite/dictionary.rb', line 24

def first_key
  order.first
end

- (Object) last_key



28
29
30
# File 'lib/kyanite/dictionary.rb', line 28

def last_key
  order.last
end

- (Object) unshift(k, v)



36
37
38
39
40
41
42
43
44
# File 'lib/kyanite/dictionary.rb', line 36

def unshift( k,v )
  unless @hash.include?( k )
    @order.unshift( k )
    @hash.store( k,v )
    true
  else
    false
  end
end