3 ms·
Yes, that would be my next top tip too. SHARPS_AND_FLATS = /\\^+ | _+ | =/x NOTES = /[a-g]/i p = <^ (?<pitch>#{SHARPS_AND_FLATS})? # sharps
by brigandish 6y ago
Yes, that would be my next top tip too.
SHARPS_AND_FLATS = /\\^+ | _+ | =/x
NOTES = /[a-g]/i
p = <^
(?<pitch>#{SHARPS_AND_FLATS})? # sharps and flats
(?<notes>#{NOTES}) # notes
( ,+ | '+ )?
( \\d* ) # duration
( / )? # fractions
( \\d* ) # more duration? I'd need to read the spec
$>x
match_data = p.match(music)
match_data[:pitch] # => "#"
match_data[:notes] # => "ADEADE"
Much more readable.