class Regexgen::State

Attributes

accepting[RW]
transitions[R]

Public Class Methods

new() click to toggle source
# File lib/regexgen/state.rb, line 8
def initialize
  @accepting = false
  @transitions = Hash.new { |hash, key| hash[key] = State.new }
end

Public Instance Methods

inspect()
Alias for: to_s
to_h() click to toggle source
# File lib/regexgen/state.rb, line 21
def to_h
  @transitions.transform_values(&:to_h).tap do |h|
    h[''] = nil if @accepting
  end
end
to_s() click to toggle source
# File lib/regexgen/state.rb, line 27
def to_s
  sigil = @accepting ? '*' : ''
  "#{sigil}#{to_h}"
end
Also aliased as: inspect
visit(visited = Set.new) click to toggle source
# File lib/regexgen/state.rb, line 13
def visit(visited = Set.new)
  return visited if visited.include?(self)

  visited.add(self)
  @transitions.each_value { |state| state.visit(visited) }
  visited
end