Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/interpolate/add/core/numeric.rb
Overview
Extension(s) for the Ruby Numeric class.
Author
License
Licensed under the MIT license.
Instance Method Summary collapse
-
#interpolate(other, balance) ⇒ Object
Returns a Float that is equal to the interpolated value between
self
andother
.
Instance Method Details
#interpolate(other, balance) ⇒ Object
Returns a Float that is equal to the interpolated value between self
and other
. balance
should be a Float from 0.0 to 1.0, where the value is a ratio between self
and other
.
A balance less than or equal to 0.0 returns self
, while a balance greater than or equal to 1.0 returns other
.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/interpolate/add/core/numeric.rb', line 21 def interpolate(other, balance) # everything should be a Float balance = balance.to_f left = self.to_f right = other.to_f # catch the easy cases return left if (balance <= 0.0) return right if (balance >= 1.0) delta = (right - left).to_f return left + (delta * balance) end |