Class: Tonal::Ratio::Approximation::Set

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tonal/approximation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ratio:) {|@ratios| ... } ⇒ Set

Returns a new instance of Set.

Yields:



159
160
161
162
163
# File 'lib/tonal/approximation.rb', line 159

def initialize(ratio:)
  @ratio = ratio
  @ratios = ::Set.new
  yield @ratios if block_given?
end

Instance Attribute Details

#ratioObject (readonly)

Returns the value of attribute ratio.



157
158
159
# File 'lib/tonal/approximation.rb', line 157

def ratio
  @ratio
end

#ratiosObject (readonly)

Returns the value of attribute ratios.



157
158
159
# File 'lib/tonal/approximation.rb', line 157

def ratios
  @ratios
end

Instance Method Details

#inspectObject



166
167
168
# File 'lib/tonal/approximation.rb', line 166

def inspect
  "#{ratio}: #{entries}"
end

#sort_byObject



170
171
172
173
174
175
176
# File 'lib/tonal/approximation.rb', line 170

def sort_by(&)
  self.class.new(ratio: ratio) do |ratios|
    entries.sort_by(&).each do |ratio|
      ratios << ratio
    end
  end
end