Станислав обнови решението на 17.10.2016 15:13 (преди около 8 години)
+def convert_between_temperature_units(temp, current_unit, wanted_unit)
+ formulas = {
+ 'CK' => temp + 273.15,
+ 'KC' => temp - 273.15,
+ 'CF' => (temp * 1.8) + 32,
+ 'FC' => (temp - 32) / 1.8,
+ 'KF' => (temp * 1.8) - 459.67,
+ 'FK' => (temp + 459.67) / 1.8,
+ 'CC' => temp,
+ 'KK' => temp,
+ 'FF' => temp
+ }
+ units = current_unit + wanted_unit
+ formulas.fetch(units)
+end
+
+def melting_point_of_substance(substance, unit)
+ substances = {
+ 'water' => 0,
+ 'ethanol' => -114,
+ 'gold' => 1064,
+ 'silver' => 961.8,
+ 'copper' => 1085
+ }
+ celsius_melting_point = substances.fetch(substance)
+ convert_between_temperature_units(celsius_melting_point, 'C', unit )
+end
+
+def boiling_point_of_substance(substance, unit)
+ substances = {
+ 'water' => 100,
+ 'ethanol' => 78.37,
+ 'gold' => 2700,
+ 'silver' => 2162,
+ 'copper' => 2567
+ }
+ celsius_boiling_point = substances.fetch(substance)
+ convert_between_temperature_units(celsius_boiling_point, 'C', unit )
+end