Class: HeadMusic::Rudiment::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/rudiment/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase (private)

Returns a new instance of Base.

Raises:

  • (NotImplementedError)


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

.registryObject (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