Created
September 7, 2010 04:24
-
-
Save rhysforyou/567864 to your computer and use it in GitHub Desktop.
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 Temperature < Numeric | |
def initialize(temp) | |
@temp = temp | |
super | |
end | |
def to_farenheit | |
9 / 5 * (@temp + 32) | |
end | |
def to_farenheit! | |
@temp = 9 / 5 * (@temp + 32) | |
end | |
def to_celcius | |
5 / 9 * (@temp - 32) | |
end | |
def to_celcius! | |
@temp = 5 / 9 * (@temp - 32) | |
end | |
end | |
=begin | |
doctest: From celcius to farenheit | |
>> Temperature.new(40).to_farenheits | |
=> 72 | |
=end | |
=begin | |
doctest: From farenheit to celcius | |
>> Temperature.new(72).to_celcius | |
=> 40 | |
=end | |
=begin | |
doctest: From celcius to farenheit permanent | |
>> temp = Temperature.new(40).to_farenheit! | |
>> temp | |
=> 72 | |
=end | |
=begin | |
doctest: From farenheit to celcius permanent | |
>> temp = Temperature.new(72).to_celcius! | |
>> temp | |
=> 40 | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment