Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/core_extensions.rb
Overview
Extends Numeric, hence Fixed & Float to_r & to_d Also adds in sign.
Instance Method Summary collapse
-
#sign ⇒ Fixnum
1 if number is positive, -1 if negative.
-
#to_degrees(mod = false) ⇒ Numeric
(also: #to_deg)
Convert Radians to Degrees.
-
#to_radians(mod = false) ⇒ Numeric
(also: #to_rad)
Converts degrees to Radians.
Instance Method Details
#sign ⇒ Fixnum
Returns 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
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
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 |