Class: DirectedEdge::CollectionHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/directed_edge.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ CollectionHash

Returns a new instance of CollectionHash.



59
60
61
# File 'lib/directed_edge.rb', line 59

def initialize(type)
  @type = type
end

Instance Method Details

#[](key) ⇒ Object



62
63
64
65
# File 'lib/directed_edge.rb', line 62

def [](key)
  self[key] = @type.new unless include? key
  super(key)
end

#eachObject



66
67
68
# File 'lib/directed_edge.rb', line 66

def each
  super { |key, value| yield(key, value) unless value.empty? }
end

#empty?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/directed_edge.rb', line 69

def empty?
  each { |key, value| return false } ; true
end