Class: Calyx::Grammar::Production::Choices
- Inherits:
-
Object
- Object
- Calyx::Grammar::Production::Choices
- Defined in:
- lib/calyx.rb
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(collection) ⇒ Choices
constructor
A new instance of Choices.
Constructor Details
#initialize(collection) ⇒ Choices
Returns a new instance of Choices.
155 156 157 |
# File 'lib/calyx.rb', line 155 def initialize(collection) @collection = collection end |
Class Method Details
.parse(productions, registry) ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/calyx.rb', line 144 def self.parse(productions, registry) choices = productions.map do |choice| if choice.is_a?(String) Concat.parse(choice, registry) elsif choice.is_a?(Symbol) NonTerminal.new(choice, registry) end end self.new(choices) end |
Instance Method Details
#evaluate ⇒ Object
159 160 161 |
# File 'lib/calyx.rb', line 159 def evaluate @collection.sample.evaluate end |