Class: Calyx::Options
- Inherits:
-
Object
- Object
- Calyx::Options
- Defined in:
- lib/calyx/options.rb
Overview
Provides access to configuration options while evaluating a grammar.
Constant Summary collapse
- DEFAULTS =
These options are used by default if not explicitly provided during initialization of the grammar.
{ strict: true }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Options
constructor
Constructs a new options instance, merging the passed in options with the defaults.
-
#merge(options) ⇒ Calyx::Options
Merges two instances together and returns a new instance.
-
#rand ⇒ Float
Returns the next pseudo-random number in the sequence defined by the internal random number generator state.
-
#rng ⇒ Random
Returns the internal random number generator instance.
-
#strict? ⇒ TrueClass, FalseClass
True if the strict mode option is enabled.
-
#to_h ⇒ Hash
Serializes instance data to a hash.
Constructor Details
Instance Method Details
#merge(options) ⇒ Calyx::Options
Merges two instances together and returns a new instance.
59 60 61 |
# File 'lib/calyx/options.rb', line 59 def merge() Options.new(@options.merge(.to_h)) end |
#rand ⇒ Float
Returns the next pseudo-random number in the sequence defined by the internal random number generator state.
The value returned is a floating point number between 0.0 and 1.0, including 0.0 and excluding 1.0.
42 43 44 |
# File 'lib/calyx/options.rb', line 42 def rand rng.rand end |
#rng ⇒ Random
Returns the internal random number generator instance. If a seed or random instance is not passed-in directly, a new instance of ‘Random` is initialized by default.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/calyx/options.rb', line 23 def rng unless @options[:rng] @options[:rng] = if @options[:seed] Random.new(@options[:seed]) else Random.new end end @options[:rng] end |
#strict? ⇒ TrueClass, FalseClass
True if the strict mode option is enabled. This option defines whether or not to raise an error on missing rules. When set to false, missing rules are skipped over when the production is concatenated.
51 52 53 |
# File 'lib/calyx/options.rb', line 51 def strict? @options[:strict] end |
#to_h ⇒ Hash
Serializes instance data to a hash.
66 67 68 |
# File 'lib/calyx/options.rb', line 66 def to_h @options.dup end |