Class: Synthra::Behaviors::Registry::BlockBehaviorInstance Private

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/behaviors/registry.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance of a block-based behavior

Wraps a block in a Base-compatible interface.

Instance Method Summary collapse

Constructor Details

#initialize(value, rng, block) ⇒ BlockBehaviorInstance

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new block behavior instance

Parameters:

  • value (Object)

    behavior configuration

  • rng (Generator::RNG, nil)

    random number generator

  • block (Proc)

    the block to call when applying



217
218
219
220
# File 'lib/synthra/behaviors/registry.rb', line 217

def initialize(value, rng, block)
  super(value, rng)
  @block = block
end

Instance Method Details

#apply(result, context = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Apply the block behavior

Parameters:

  • result (Object)

    generated data

  • context (Generator::Context, nil) (defaults to: nil)

    generation context

Returns:

  • (Object)

    result from block



230
231
232
233
234
# File 'lib/synthra/behaviors/registry.rb', line 230

def apply(result, context = nil)
  return result unless should_apply?

  @block.call(context, result, value)
end