Sha256: 0b237ed537e9ffdcfd7327714ff79fdcdac78ab7e407dd58b597a7be999d4846

Contents?: true

Size: 669 Bytes

Versions: 4

Compression:

Stored size: 669 Bytes

Contents

# frozen_string_literal: true

require_relative '../edge'

module Tangle
  module Directed
    #
    # An edge in a directed graph
    #
    class Edge < Tangle::Edge
      attr_reader :head, :tail

      def head?(vertex)
        @head == vertex
      end

      def tail?(vertex)
        @tail == vertex
      end

      def each_vertex(&block)
        [@tail, @head].each(&block)
      end

      def to_s
        "{#{@tail}-->#{@head}}"
      end
      alias inspect to_s

      private

      def initialize_vertices(tail, head = tail)
        super
        @tail = tail
        @head = head
        @vertices = { tail => head }.freeze
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tangle-0.11.0 lib/tangle/directed/edge.rb
tangle-0.10.2 lib/tangle/directed/edge.rb
tangle-0.10.1 lib/tangle/directed/edge.rb
tangle-0.10.0 lib/tangle/directed/edge.rb