Just call it, for example like:

0.5.scale_between(0, 1, 100, 200)
The result would be 150.

Source Code : 
class Numeric
  def scale_between
(from_minfrom_maxto_minto_max)
    ((
to_max to_min) * (self from_min)) / (from_max from_min) + to_min

[Login or Register to remove this advertisement]

  end
end 
Mobile_Guru Reviewed by Mobile_Guru on . Scale a number into a defined range Just call it, for example like: The result would be 150. class Numeric def scale_between(from_min, from_max, to_min, to_max) ((to_max - to_min) * (self - from_min)) / (from_max - from_min) + to_min end end Rating: 5