Class: Graph::Edge

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

Overview

An edge. This class is just a wrapper around a hash of attributes since in version <= 0.1.5 edges were simple hashes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = nil) ⇒ Edge

Returns a new instance of Edge.



88
89
90
# File 'lib/graph.rb', line 88

def initialize(attrs=nil)
    @attrs = attrs || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/graph.rb', line 104

def method_missing(method, *args, &block)

    return @attrs[method.to_sym] if @attrs.has_key? method.to_sym
    return @attrs[method.to_s] if @attrs.has_key? method.to_s

    @attrs.send(method, *args, &block)
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



86
87
88
# File 'lib/graph.rb', line 86

def attrs
  @attrs
end

Instance Method Details

#==(other) ⇒ Object

compare two edges

Parameters:



94
95
96
97
98
# File 'lib/graph.rb', line 94

def ==(other)
    return false if !other.is_a?(Edge)

    @attrs == other.attrs
end

#update(h) ⇒ Object



100
101
102
# File 'lib/graph.rb', line 100

def update(h)
    Edge.new super(h)
end