Class: Dictionary
- Defined in:
- lib/kyanite/dictionary.rb
Overview
Dictionary Additions
- Kyanite definitions
- 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
- #-(other) ⇒ Object
- #each_with_index ⇒ Object
- #fetch_by_index(index) ⇒ Object
- #first_key ⇒ Object
- #last_key ⇒ Object
- #unshift(k, v) ⇒ Object
Instance Method Details
#-(other) ⇒ Object
32 33 34 |
# File 'lib/kyanite/dictionary.rb', line 32 def -(other) (self.to_a - other.to_a).to_dictionary end |
#each_with_index ⇒ Object
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 |
#fetch_by_index(index) ⇒ Object
20 21 22 |
# File 'lib/kyanite/dictionary.rb', line 20 def fetch_by_index(index) @hash[order[index]] end |
#first_key ⇒ Object
24 25 26 |
# File 'lib/kyanite/dictionary.rb', line 24 def first_key order.first end |
#last_key ⇒ Object
28 29 30 |
# File 'lib/kyanite/dictionary.rb', line 28 def last_key order.last end |
#unshift(k, v) ⇒ Object
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 |