Created
October 6, 2015 06:13
-
-
Save eternal44/75db663904aaef476cca to your computer and use it in GitHub Desktop.
No argument in conversion methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UnitConversion | |
| def initialize(measurement, unit) | |
| @measurement = measurement | |
| @unit = unit | |
| end | |
| # Proxy with Kelvin | |
| def to_kelvin | |
| case @unit | |
| when 'celcius' | |
| @measurement += 273.15 | |
| when 'rankine' | |
| @measurement /= 1.8 | |
| when 'fahrenheit' | |
| @measurement = (@measurement + 459.67) * 5 / 9 | |
| end | |
| end | |
| def to_celcius | |
| case @unit | |
| when 'kelvin' | |
| @measurement -= 273.15 | |
| when 'fahrenheit' | |
| self.to_kelvin | |
| @unit = 'kelvin' | |
| self.to_celcius | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment