Class: Hegel::Generators::OptionalGenerator
- Inherits:
-
Hegel::Generator
- Object
- Hegel::Generator
- Hegel::Generators::OptionalGenerator
- Defined in:
- lib/hegel/generators.rb,
sig/hegel.rbs
Overview
Hegel::Syntax::Methods#optional. Draws from generator with
probability 0.5, nil otherwise. Does not expose a p: keyword: this
milestone leaves generate_boolean at its own default probability.
Instance Method Summary collapse
- #do_draw(tc) ⇒ Object
-
#initialize(generator) ⇒ OptionalGenerator
constructor
A new instance of OptionalGenerator.
Methods inherited from Hegel::Generator
Constructor Details
#initialize(generator) ⇒ OptionalGenerator
Returns a new instance of OptionalGenerator.
251 252 253 254 |
# File 'lib/hegel/generators.rb', line 251 def initialize(generator) super() @generator = generator end |
Instance Method Details
#do_draw(tc) ⇒ Object
256 257 258 259 260 261 262 263 |
# File 'lib/hegel/generators.rb', line 256 def do_draw(tc) tc.start_span(LibHegel::HEGEL_LABEL_OPTIONAL) begin tc.generate_boolean ? @generator.do_draw(tc) : nil ensure tc.stop_span(discard: false) end end |