Антон обнови решението на 17.10.2016 00:57 (преди около 8 години)
+def convert_between_temperature_units(degrees, from, to)
+ if from == 'C' && to == 'F'
+ (9.0 / 5 * degrees) + 32
+ elsif from == 'C' && to == 'K'
+ degrees + 273.15
+ elsif from == 'F' && to == 'C'
+ 5.0 / 9 * (degrees - 32)
+ elsif from == 'F' && to == 'K'
+ 5.0 / 9 * (degrees - 32) + 273.15
+ elsif from == 'K' && to == 'F'
+ 9.0 / 5 * (degrees - 273.15) + 32
+ elsif from == 'K' && to == 'C'
+ degrees - 273.15
+ end
+end
+
+def convert_from_celsius_in_hash(hash, substance, unit)
+ if unit == 'C'
+ hash[substance]
+ else
+ convert_between_temperature_units(hash[substance], 'C', unit)
+ end
+end
+
+def melting_point_of_substance(substance, unit)
+ melting_point_in_c = {'water' => 0, 'ethanol' => -144, 'gold' => 1_064, 'silver' => 961.8, 'copper' => 1_085}
+ convert_from_celsius_in_hash(melting_point_in_c, substance, unit)
+end
+
+def boiling_point_of_substance(substance, unit)
+ boiling_point_in_c = {'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700, 'silver' => 2_162, 'copper' => 2_567}
+ convert_from_celsius_in_hash(boiling_point_in_c, substance, unit)
+end