Module: Tonal::IRBHelpers

Defined in:
lib/tonal/irb_helpers.rb

Instance Method Summary collapse

Instance Method Details

#i(*args, reduced: true) ⇒ Tonal::Interval

Returns the interval between the given args.

Examples:

i(2,3) => (3/2) ((3/2) / (1/1))

Parameters:

  • args

    two arguments representing ratios or four arguments representing two pairs of numerator/denominator

  • reduced (defaults to: true)

    boolean determining whether to use Tonal::ReducedRatio or Tonal::Ratio

Returns:



29
30
31
# File 'lib/tonal/irb_helpers.rb', line 29

def i(*args, reduced: true)
  Tonal::Interval.new(*args, reduced:)
end

#r(arg1, arg2 = nil) ⇒ Tonal::Ratio

Returns an unreduced ratio.

Examples:

r(3,3) => (3/3)

Parameters:

  • arg1

    the ratio if only argument provided, or the numerator if two argments are provided

  • arg2 (defaults to: nil)

    the denominator when two arguments are provided

Returns:



9
10
11
# File 'lib/tonal/irb_helpers.rb', line 9

def r(arg1, arg2=nil)
  Tonal::Ratio.new(arg1, arg2)
end

#rr(arg1, arg2 = nil) ⇒ Tonal::ReducedRatio

Returns a reduced ratio.

Examples:

rr(3,3) => (1/1)

Parameters:

  • arg1

    the ratio if only argument provided, or the numerator if two argments are provided

  • arg2 (defaults to: nil)

    the denominator when two arguments are provided

Returns:



19
20
21
# File 'lib/tonal/irb_helpers.rb', line 19

def rr(arg1, arg2=nil)
  Tonal::ReducedRatio.new(arg1, arg2)
end