class Society::Edge

The Edge class represents an edge between two nodes in a graph. An edge is assumed to represent a direct relationship between two Classes or Modules.

Attributes

to[R]
weight[R]

Public Class Methods

new(to:, weight: 1) click to toggle source

Public: Create a new Edge.

to - Node to target. weight - Weight of the edge, representing the number of references to the

node referenced.  (Default: 1)
# File lib/society/edge.rb, line 14
def initialize(to:, weight: 1)
  @to     = to
  @weight = weight
end

Public Instance Methods

+(edge) click to toggle source

Public: Add two Edges' weights, returning a new Edge.

edge - An Edge.

Returns a new Edge if both edges target the same node. Returns nil otherwise.

# File lib/society/edge.rb, line 25
def +(edge)
  return nil unless edge.to == to

  Edge.new(to: to, weight: weight + edge.weight)
end
inspect()
Alias for: to_s
to_s() click to toggle source

Public: Return the name of the node to which the edge points.

Returns a string.

# File lib/society/edge.rb, line 34
def to_s
  to.to_s
end
Also aliased as: inspect