Skip to content

Instantly share code, notes, and snippets.

@eternal44
Created August 21, 2015 02:24
Show Gist options
  • Save eternal44/f267d1c3d197768a0fc5 to your computer and use it in GitHub Desktop.
Save eternal44/f267d1c3d197768a0fc5 to your computer and use it in GitHub Desktop.
Design pattern example for temperature conversions
def kelvin_to_rankine(value)
value * 1.8
end
def rankine_to_kelvin(value)
value / 1.8
end
def rankine_to_celcius(value)
value_holder = rankine_to_kelvin(value)
kelvin_to_celcius(value_holder)
end
def rankine_to_fahrenheit(value)
value_holder = rankine_to_kelvin(value)
kelvin_to_fahrenheit(value_holder)
end
def celcius_to_rankine(value)
value_holder = celcius_to_kelvin(value)
kelvin_to_rankine(value_holder)
end
def fahrenheit_to_rankine(value)
value_holder = fahrenheit_to_kelvin(value)
kelvin_to_rankine(value_holder)
end
@eternal44
Copy link
Author

Using kelvins as a medium for conversions instead of writing individual conversions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment