# frozen_string_literal: true # Consonance is a description of intervals that sound more pleasing. class HeadMusic::Consonance LEVELS = %w[perfect imperfect dissonant].freeze def self.get(name) @consonances ||= {} @consonances[name.to_sym] ||= new(name) if LEVELS.include?(name.to_s) end attr_reader :name delegate :to_s, to: :name def initialize(name) @name = name.to_s.to_sym end def ==(other) to_s == other.to_s end LEVELS.each do |method_name| define_method(:"#{method_name}?") { to_s == method_name } end end