Божидар обнови решението на 16.10.2016 22:46 (преди около 8 години)
+def convert_between_temperature_units(src_degs, src_unit, dest_unit)
+ converters = [
+ -> (c_degs) { c_degs * 9.0 / 5 + 32 },
+ -> (f_degs) { (f_degs + 459.67) * 5.0 / 9 },
+ -> (k_degs) { k_degs - 273.15 }
+ ]
+ from_index = 'CFK'.index(src_unit)
+ to_index = ('CFK' * 2).index(dest_unit, from_index)
+ converter_chain = (converters * 2)[from_index...to_index]
+ converter_chain.reduce(src_degs) { |acc, f| f.call(acc) }
+end
+
+def get_degs_and_convert_units(degree_source, substance, unit)
+ degrees = degree_source[substance]
+ convert_between_temperature_units(degrees, 'C', unit)
+end
+
+def melting_point_of_substance(substance, unit)
+ melting_points_in_c = {
+ 'water' => 0, 'ethanol' => -114, 'gold' => 1064,
+ 'silver' => 961.8, 'copper' => 1085
+ }
+ get_degs_and_convert_units(melting_points_in_c, substance, unit)
+end
+
+def boiling_point_of_substance(substance, unit)
+ boling_points_in_c = {
+ 'water' => 100, 'ethanol' => 78.37, 'gold' => 2700,
+ 'silver' => 2162, 'copper' => 2567
+ }
+ get_degs_and_convert_units(boling_points_in_c, substance, unit)
+end