Class: Tetsujin::Theory::Notes
- Inherits:
-
Object
- Object
- Tetsujin::Theory::Notes
- Extended by:
- Forwardable
- Defined in:
- lib/tetsujin/theory/notes.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
Instance Method Summary collapse
-
#+(other) ⇒ Tetsujin::Theory::Notes
2つの音の和集合.
-
#==(other) ⇒ Boolean
同じ音を持つかどうか.
-
#initialize(notes:) ⇒ Notes
constructor
A new instance of Notes.
Constructor Details
Instance Attribute Details
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
9 10 11 |
# File 'lib/tetsujin/theory/notes.rb', line 9 def notes @notes end |
Instance Method Details
#+(other) ⇒ Tetsujin::Theory::Notes
Returns 2つの音の和集合.
32 33 34 35 |
# File 'lib/tetsujin/theory/notes.rb', line 32 def +(other) new_notes = (notes + other.notes).uniq.sort Tetsujin::Theory::Notes.new(notes: new_notes) end |
#==(other) ⇒ Boolean
Returns 同じ音を持つかどうか.
20 21 22 23 24 25 26 27 28 |
# File 'lib/tetsujin/theory/notes.rb', line 20 def ==(other) self_sorted = notes.sort do |a, b| [a.octave, a.pitch_class] <=> [b.octave, b.pitch_class] end other_sorted = other.notes.sort do |a, b| [a.octave, a.pitch_class] <=> [b.octave, b.pitch_class] end self_sorted == other_sorted end |