Class: Calyx::Syntax::Unique

Inherits:
Object
  • Object
show all
Defined in:
lib/calyx/syntax/unique.rb

Overview

A type of production rule representing a unique substitution which only returns values that have not previously been selected. The probability that a given rule will be selected increases as more selections are made and the list grows smaller.

Constant Summary collapse

SIGIL =
'$'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(symbol, registry) ⇒ Unique

Construct a unique rule, given the symbol to lookup and the registry to look it up in.

Parameters:



15
16
17
18
# File 'lib/calyx/syntax/unique.rb', line 15

def initialize(symbol, registry)
  @symbol = symbol.slice(1, symbol.length-1).to_sym
  @registry = registry
end

Instance Method Details

#evaluate(options) ⇒ Array

Evaluate the unique rule, using the registry to handle the expansion and keep track of previous selections.

Parameters:

Returns:

  • (Array)


25
26
27
# File 'lib/calyx/syntax/unique.rb', line 25

def evaluate(options)
  [@symbol, @registry.unique_expansion(@symbol)]
end