Class: ColtraneInstruments::Guitar::String
- Inherits:
-
Object
- Object
- ColtraneInstruments::Guitar::String
- Defined in:
- lib/coltrane_instruments/guitar/string.rb
Instance Attribute Summary collapse
-
#guitar ⇒ Object
readonly
Returns the value of attribute guitar.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
Instance Method Summary collapse
- #+(fret) ⇒ Object
- #find(pitch_class, possible_frets: (0..guitar.frets).to_a) ⇒ Object
-
#initialize(pitch, guitar:) ⇒ String
constructor
A new instance of String.
Constructor Details
#initialize(pitch, guitar:) ⇒ String
Returns a new instance of String.
8 9 10 11 |
# File 'lib/coltrane_instruments/guitar/string.rb', line 8 def initialize(pitch, guitar:) @guitar = guitar @pitch = pitch end |
Instance Attribute Details
#guitar ⇒ Object (readonly)
Returns the value of attribute guitar.
6 7 8 |
# File 'lib/coltrane_instruments/guitar/string.rb', line 6 def guitar @guitar end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
6 7 8 |
# File 'lib/coltrane_instruments/guitar/string.rb', line 6 def pitch @pitch end |
Instance Method Details
#+(fret) ⇒ Object
24 25 26 |
# File 'lib/coltrane_instruments/guitar/string.rb', line 24 def +(fret) pitch + fret end |
#find(pitch_class, possible_frets: (0..guitar.frets).to_a) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/coltrane_instruments/guitar/string.rb', line 13 def find(pitch_class, possible_frets: (0..guitar.frets).to_a) output = [] n = 0 loop do f = (pitch_class.integer - pitch.integer) % 12 + 12 * n possible_frets.include?(f) ? output << Note.new(self, f) : break n += 1 end output end |