Module KeyContext
In: app/models/key_context.rb

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.

Methods

Public Class methods

[Source]

    # File app/models/key_context.rb, line 10
10:         def self.included(klass)
11:                 klass.class_eval do
12:                         attr_accessor :key
13:                         
14:                         def in_key_of(name)
15:                                 self.key = Key.find_by_name(name)
16:                                 self
17:                         end
18:                         alias_method :in, :in_key_of
19:                         
20:                         def without_key
21:                                 self.key = nil
22:                                 self
23:                         end
24:                 end
25:         end

Public Instance methods

[Source]

    # File app/models/key_context.rb, line 14
14:                         def in_key_of(name)
15:                                 self.key = Key.find_by_name(name)
16:                                 self
17:                         end

[Source]

    # File app/models/key_context.rb, line 20
20:                         def without_key
21:                                 self.key = nil
22:                                 self
23:                         end

[Validate]