Module: Musa::Extension::Arrayfy
- Defined in:
- lib/musa-dsl/core-ext/arrayfy.rb
Overview
Note:
This refinement must be activated with using Musa::Extension::Arrayfy
Note:
Arrays are cloned and singleton class modules are preserved
Refinement that converts any object to an array, with optional repetition and defaults.
This refinement is essential for normalizing parameters in the DSL, allowing users to provide either single values or arrays and have them processed uniformly.
Core Behavior
- Object: Wraps in array; nil becomes []
- Array: Returns clone or cycles to requested size
- size parameter: Repeats/cycles to achieve target length
- default parameter: Replaces nil values
Use Cases
- Normalizing velocity parameters (single value or per-note array)
- Ensuring consistent array handling in DSL methods
- Cycling patterns to fill required lengths
- Providing default values for missing data
Methods Added
Object
- Object#arrayfy - Converts any object into an array, optionally repeated to a target size
Array
- Array#arrayfy - Clones or cycles the array to achieve the target size, with nil replacement