Александър обнови решението на 16.10.2016 11:43 (преди около 8 години)
+WATER_CHANGING_POINTS = [0, 100]
+ETHANOL_CHANGING_POINTS = [-114, 78.37]
+GOLD_CHANGING_POINTS = [1064, 2700]
+SILVER_CHANGING_POINTS = [961.8, 2162]
+COPPER_CHANGING_POINTS = [1085, 2567]
+
+MELTING_POINT = 0
+BOILING_POINT = 1
+
+def convert_between_temperature_units(deg, from, to)
+ case from
+ when 'C'
+ convert_celsius(deg, to)
+ when 'K'
+ convert_kelvin(deg, to)
+ when 'F'
+ convert_fahrenheit(deg, to)
+ end
+end
+
+def convert_celsius(deg, to)
+ case to
+ when 'K'
+ deg + 273.15
+ when 'F'
+ (deg * 1.8) + 32
+ else
+ deg
+ end
+end
+
+def convert_fahrenheit(deg, to)
+ case to
+ when 'K'
+ (deg + 459.67) / 1.8
+ when 'C'
+ (deg - 32) / 1.8
+ else
+ deg
+ end
+end
+
+def convert_kelvin(deg, to)
+ case to
+ when 'C'
+ deg - 273.15
+ when 'F'
+ (deg * 1.8) - 459.67
+ else
+ deg
+ end
+end
+
+def melting_point_of_substance(substance, deg_type)
+ case substance
+ when 'water'
+ operating_temp = WATER_CHANGING_POINTS[MELTING_POINT]
+ when 'ethanol'
+ operating_temp = ETHANOL_CHANGING_POINTS[MELTING_POINT]
+ when 'gold'
+ operating_temp = GOLD_CHANGING_POINTS[MELTING_POINT]
+ when 'silver'
+ operating_temp = SILVER_CHANGING_POINTS[MELTING_POINT]
+ when 'copper'
+ operating_temp = COPPER_CHANGING_POINTS[MELTING_POINT]
+ end
+ convert_between_temperature_units(operating_temp, 'C', deg_type)
+end
+
+def boiling_point_of_substance(substance, deg_type)
+ case substance
+ when 'water'
+ operating_temp = WATER_CHANGING_POINTS[BOILING_POINT]
+ when 'ethanol'
+ operating_temp = ETHANOL_CHANGING_POINTS[BOILING_POINT]
+ when 'gold'
+ operating_temp = GOLD_CHANGING_POINTS[BOILING_POINT]
+ when 'silver'
+ operating_temp = SILVER_CHANGING_POINTS[BOILING_POINT]
+ when 'copper'
+ operating_temp = COPPER_CHANGING_POINTS[BOILING_POINT]
+ end
+ convert_between_temperature_units(operating_temp, 'C', deg_type)
+end
Погледни последната лекция за Hash
-ове и виж дали не могат да ти помогнат да си опростиш решението.