Class: PDF::Writer::OHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb

Overview

Based on [ruby-talk:20551]. Updated to (hopefully) be 1.8 friendly.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ OHash

Returns a new instance of OHash.



16
17
18
19
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 16

def initialize(*args)
  @keys = []
  super
end

Instance Method Details

#[]=(key, val) ⇒ Object



21
22
23
24
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 21

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

#delete(key) ⇒ Object



26
27
28
29
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 26

def delete(key)
  @keys.delete(key) if has_key?(key)
  super
end

#eachObject



31
32
33
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 31

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

#each_keyObject



35
36
37
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 35

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

#each_pairObject



14
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 14

alias_method :each_pair, :each

#each_valueObject



39
40
41
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 39

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

#firstObject



43
44
45
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 43

def first
  self[@keys[0]]
end

#first?(item) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 51

def first?(item)
  self[@keys[0]] == item
end

#lastObject



47
48
49
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 47

def last
  self[@keys[-1]]
end

#last?(item) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 55

def last?(item)
  self[@keys[-1]] == item
end

#storeObject



13
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb', line 13

alias_method :store, :[]=