Skip to content

Instantly share code, notes, and snippets.

@eternal44
Created October 6, 2015 06:13
Show Gist options
  • Save eternal44/75db663904aaef476cca to your computer and use it in GitHub Desktop.
Save eternal44/75db663904aaef476cca to your computer and use it in GitHub Desktop.
No argument in conversion methods
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