Rosetta Code
Temperature conversion
Convert fixed Celsius and Fahrenheit values with straightforward formulae.
Source
rosettacode/popular/temperature_conversion.vibe
# title: Temperature conversion
# source: https://rosettacode.org/wiki/Temperature_conversion
# category: Rosetta Code
# difficulty: Intro
# summary: Convert fixed Celsius and Fahrenheit values with straightforward formulae.
# tags: popular, math, conversion, basics
# vibe: 0.2
def celsius_to_fahrenheit(value)
(value * 9 / 5) + 32
end
def fahrenheit_to_celsius(value)
(value - 32) * 5 / 9
end
def celsius_to_kelvin(value)
value + 273.15
end
def run
{
freezing_point: {
celsius: 0,
fahrenheit: celsius_to_fahrenheit(0),
kelvin: celsius_to_kelvin(0)
},
boiling_point: {
celsius: 100,
fahrenheit: celsius_to_fahrenheit(100),
kelvin: celsius_to_kelvin(100)
},
room_temperature_fahrenheit: {
fahrenheit: 68,
celsius: fahrenheit_to_celsius(68)
}
}
end
Output
Press run to execute run from this example.