Class: Calyx::Syntax::Unique
- Inherits:
-
Object
- Object
- Calyx::Syntax::Unique
- 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
-
#evaluate(options) ⇒ Array
Evaluate the unique rule, using the registry to handle the expansion and keep track of previous selections.
-
#initialize(symbol, registry) ⇒ Unique
constructor
Construct a unique rule, given the symbol to lookup and the registry to look it up in.
Constructor Details
#initialize(symbol, registry) ⇒ Unique
Construct a unique rule, given the symbol to lookup and the registry to look it up in.
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.
25 26 27 |
# File 'lib/calyx/syntax/unique.rb', line 25 def evaluate() [@symbol, @registry.unique_expansion(@symbol)] end |