Module: Musa::Extension::Hashify
- Defined in:
- lib/musa-dsl/core-ext/hashify.rb
Overview
Note:
This refinement must be activated with using Musa::Extension::Hashify
Note:
Singleton class modules (dataset extensions) are preserved on hash results
Refinement that converts objects, arrays, and hashes into hashes with specified keys.
This refinement is crucial for normalizing parameters in the DSL, especially when dealing with musical events that can be specified in multiple formats (positional, hash-based, or mixed).
Core Behavior
- Object: Creates hash mapping all keys to the same value
- Array: Maps keys to array elements in order (consuming array)
- Hash: Filters and reorders according to specified keys
- Preserves singleton class modules on hash results
Use Cases
- Converting positional parameters to named parameters
- Normalizing mixed parameter formats in musical events
- Extracting specific keys from larger hashes
- Providing defaults for missing event attributes
Methods Added
Object
- Object#hashify - Creates a hash mapping all specified keys to this object's value
Array
- Array#hashify - Maps array elements to hash keys in order, consuming the array
Hash
- Hash#hashify - Filters and reorders hash to include only specified keys, preserving modules