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.



56
57
58
# File 'lib/directed_edge.rb', line 56

def initialize(type)
  @type = type
end

Instance Method Details

#[](key) ⇒ Object



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

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

#eachObject



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

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