Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/core_ext/numeric.rb
Class Method Summary collapse
-
.tick_interval ⇒ Object
The game tick interval.
-
.tick_interval=(value) ⇒ Object
Set the tick interval which is used in conversion of seconds to ticks.
Instance Method Summary collapse
- #degrees ⇒ Object
- #radians ⇒ Object
-
#second ⇒ Object
(also: #seconds, #secs, #sec)
Provides the suffix ‘second’ which will translate seconds to game ticks.
-
#tick ⇒ Object
(also: #ticks)
Provides the suffix ‘tick’ which will simply express the number with a vanity suffix.
-
#to_degrees ⇒ Object
Convert the specified numeric value in radians to degrees.
-
#to_radians ⇒ Object
Convert the specified numeric value in degrees to radians.
Class Method Details
.tick_interval ⇒ Object
Returns the game tick interval. By default the tick interval is 16.66666.
14 15 16 |
# File 'lib/core_ext/numeric.rb', line 14 def self.tick_interval @tick_interval.to_f == 0 ? 16.666666 : @tick_interval.to_f end |
.tick_interval=(value) ⇒ Object
Set the tick interval which is used in conversion of seconds to ticks.
7 8 9 |
# File 'lib/core_ext/numeric.rb', line 7 def self.tick_interval=(value) @tick_interval = value.to_f end |
Instance Method Details
#degrees ⇒ Object
63 64 65 |
# File 'lib/core_ext/numeric.rb', line 63 def degrees self end |
#radians ⇒ Object
59 60 61 |
# File 'lib/core_ext/numeric.rb', line 59 def radians self end |
#second ⇒ Object Also known as: seconds, secs, sec
Provides the suffix ‘second’ which will translate seconds to game ticks. This is to allow for a number of seconds to be expressed in situations where game ticks are used (e.g. animations).
33 34 35 |
# File 'lib/core_ext/numeric.rb', line 33 def second (self * 1000 / Numeric.tick_interval).floor end |
#tick ⇒ Object Also known as: ticks
Provides the suffix ‘tick’ which will simply express the number with a vanity suffix.
53 54 55 |
# File 'lib/core_ext/numeric.rb', line 53 def tick self end |
#to_degrees ⇒ Object
Convert the specified numeric value in radians to degrees
68 69 70 |
# File 'lib/core_ext/numeric.rb', line 68 def to_degrees self * 180 / Math::PI end |
#to_radians ⇒ Object
Convert the specified numeric value in degrees to radians
73 74 75 |
# File 'lib/core_ext/numeric.rb', line 73 def to_radians self * Math::PI / 180 end |