class RGL::Edge::DirectedEdge

An {Edge} is simply a directed pair +(source -> target)+. Most library functions try do omit to instantiate edges. They instead use two vertex parameters for representing edges (see {Graph#each_edge}). If a client wants to store edges explicitly {DirectedEdge} or {UnDirectedEdge} instances are returned (i.e. {Graph#edges}).

Attributes

source[RW]
target[RW]

Public Class Methods

[](*a) click to toggle source

Can be used to create an edge from a two element array.

   # File lib/rgl/base.rb
39 def self.[](*a)
40   new(a[0], a[1])
41 end
new(a, b) click to toggle source

Create a new DirectedEdge with source a and target b.

   # File lib/rgl/base.rb
45 def initialize(a, b)
46   @source, @target = a, b
47 end

Public Instance Methods

<=>(e) click to toggle source

Sort support is dispatched to the <=> method of Array

   # File lib/rgl/base.rb
93 def <=> e
94   self.to_a <=> e.to_a
95 end
==(edge)
Alias for: eql?
[](index) click to toggle source

Edges can be indexed. +edge.at(0) == edge.source+, +edge.at(n) == edge.target+ for all +n>0+. Edges can thus be used as a two element array.

   # File lib/rgl/base.rb
70 def [](index)
71   index.zero? ? source : target
72 end
eql?(edge) click to toggle source

Two directed edges (u,v) and (x,y) are equal iff u == x and v == y. eql? is needed when edges are inserted into a Set. eql? is aliased to +==+.

   # File lib/rgl/base.rb
51 def eql?(edge)
52   (source == edge.source) && (target == edge.target)
53 end
Also aliased as: ==
hash() click to toggle source
   # File lib/rgl/base.rb
57 def hash
58   source.hash ^ target.hash
59 end
inspect()

Since Ruby 2.0 inspect no longer calls to_s. So we alias it to to_s (fixes #22)

Alias for: to_s
reverse() click to toggle source

Returns (v,u) if self == (u,v). @return [Edge]

   # File lib/rgl/base.rb
63 def reverse
64   self.class.new(target, source)
65 end
to_a() click to toggle source

Returns the array [source,target]. @return [Array]

   # File lib/rgl/base.rb
87 def to_a
88   [source, target]
89 end
to_s() click to toggle source

Returns string representation of the edge @example

DirectedEdge[1,2].to_s == "(1-2)"

@return [String]

   # File lib/rgl/base.rb
78 def to_s
79   "(#{source}-#{target})"
80 end
Also aliased as: inspect