Стамен обнови решението на 16.10.2016 12:16 (преди около 8 години)
+def convert_between_temperature_units(degree, input, output)
+ if input == output
+ degree
+ elsif input == 'C' && output == 'F'
+ degree * 1.8 + 32
+ elsif input == 'C' && output == 'K'
+ degree + 273.15
+ elsif input == 'K' && output == 'F'
+ degree * 9 / 5 - 459.67
+ elsif input == 'K' && output == 'C'
+ degree - 273.15
+ elsif input == 'F' && output == 'C'
+ (degree - 32) / 1.8
+ elsif input == 'F' && output == 'K'
+ (degree + 459.67) * 5 / 9
+ end
+end
+
+def melting_point_of_substance(element, measure)
+ if element == 'water'
+ convert_between_temperature_units(0, 'C', measure)
+ elsif element == 'ethanol'
+ convert_between_temperature_units(-114, 'C', measure)
+ elsif element == 'gold'
+ convert_between_temperature_units(1064, 'C', measure)
+ elsif element == 'silver'
+ convert_between_temperature_units(961.8, 'C', measure)
+ elsif element == 'copper'
+ convert_between_temperature_units(1085, 'C', measure)
+ end
+end
+
+def boiling_point_of_substance(element, measure)
+ if element == 'water'
+ convert_between_temperature_units(100, 'C', measure)
+ elsif element == 'ethanol'
+ convert_between_temperature_units(78.37, 'C', measure)
+ elsif element == 'gold'
+ convert_between_temperature_units(2700, 'C', measure)
+ elsif element == 'silver'
+ convert_between_temperature_units(2162, 'C', measure)
+ elsif element == 'copper'
+ convert_between_temperature_units(2567, 'C', measure)
+ end
+end
Погледни последната лекция за Hash
-ове и виж дали не могат да ти помогнат да си опростиш решението.