Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/core_extensions.rb

Overview

Extends Numeric, hence Fixed & Float to_r & to_d Also adds in sign.

Instance Method Summary collapse

Instance Method Details

#signFixnum

Returns 1 if number is positive, -1 if negative.

Returns:

  • (Fixnum)

    1 if number is positive, -1 if negative.



32
33
34
# File 'lib/core_extensions.rb', line 32

def sign
  self < 0 ? -1 : 1
end

#to_degrees(mod = false) ⇒ Numeric Also known as: to_deg

Convert Radians to Degrees

Parameters:

  • mod (true, false) (defaults to: false)

    Optional argument mod == true, then applies % 360

Returns:



9
10
11
12
13
14
15
# File 'lib/core_extensions.rb', line 9

def to_degrees(mod = false)
  if mod
    (self * 180 / Math::PI) % 360
  else
    self * 180 / Math::PI
  end
end

#to_radians(mod = false) ⇒ Numeric Also known as: to_rad

Converts degrees to Radians

Parameters:

  • mod (true, false) (defaults to: false)

    Optional argument mod == true, then applies % Math::PI

Returns:



20
21
22
23
24
25
26
# File 'lib/core_extensions.rb', line 20

def to_radians(mod = false)
  if mod
    (self * Math::PI / 180) % Math::PI
  else
    self * Math::PI / 180
  end
end