Class: HeadMusic::Rudiment::Base
- Inherits:
-
Object
- Object
- HeadMusic::Rudiment::Base
- Defined in:
- lib/head_music/rudiment/base.rb
Direct Known Subclasses
Alteration, ChromaticInterval, Clef, Consonance, KeySignature, LetterName, Meter, Pitch, PitchClass, Quality, ReferencePitch, Register, RhythmicElement, RhythmicUnit, Scale, ScaleDegree, ScaleType, Solmization, Spelling, TonalContext, Tuning, UnpitchedSound
Class Method Summary collapse
-
.fetch_or_register(key, *arguments) ⇒ Object
private
Builds only on a miss, from the key itself unless the rudiment takes something else – a key is often already the value it identifies.
-
.registry ⇒ Object
private
Rudiments are values: the C♯ in one chord is the C♯ in another, so each one is built once and looked up by key from then on.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
private
A new instance of Base.
Constructor Details
#initialize ⇒ Base (private)
Returns a new instance of Base.
27 28 29 |
# File 'lib/head_music/rudiment/base.rb', line 27 def initialize raise NotImplementedError, "Cannot instantiate abstract rudiment base class" end |
Class Method Details
.fetch_or_register(key, *arguments) ⇒ Object (private)
Builds only on a miss, from the key itself unless the rudiment takes something else – a key is often already the value it identifies.
18 19 20 21 |
# File 'lib/head_music/rudiment/base.rb', line 18 def self.fetch_or_register(key, *arguments) arguments = [key] if arguments.empty? registry[key] ||= new(*arguments) end |
.registry ⇒ Object (private)
Rudiments are values: the C♯ in one chord is the C♯ in another, so each one is built once and looked up by key from then on. Identity is the point – equal rudiments are the same object, and a spelling can be compared with equal? without anyone having written ==.
The registry is per class rather than per hierarchy: the ivar is set on whichever class the call arrives at, so Note and Rest keep their own even though both inherit this from RhythmicElement.
12 13 14 |
# File 'lib/head_music/rudiment/base.rb', line 12 def self.registry @registry ||= {} end |