Module: JazzModel::KeyContext

Included in:
Chord, Mode, NotesCollection, Scale
Defined in:
lib/jazz_model/key_context.rb

Overview

Key context is a module intended to be mixed in to classes requiring the notion of “key context”. Concepts such as chords and scales exist as mathematical relationships absent key, but can be put into key context. Adds a key instance variable to the including class and two new methods:

  • in_key_of(new_key) - Sets the key context to the specified new_key.

  • without_key - Removes key context.

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jazz_model/key_context.rb', line 11

def self.included(klass)
	klass.class_eval do
		attr_accessor :key

		def in_key_of(name)
			self.key = Key.find_by_name(name)
			self
		end
		alias_method :in, :in_key_of

		def without_key
			self.key = nil
			self
		end
	end
end