In our previous challenge, we explored one way to pass a variable number of
arguments to our methods. While it may seem handy feature to have, except few
circumstances, you are never going to use that many variables for your method.
Also, if your are passing several different types of variables to the method which
then will be assigned to the array, it can be difficult for the programmer
invoking the method to remember the proper order for those arguments.
Ruby allows you to (partially) mitigate this problem by passing a Hash as an
argument or one of the arguments. For example, you have a method that takes a
URI to download a file and another argument containing a Hash of other named
options (proxy, timeout, active-connections etc.,)
The main problem with this technique, however, is that you cannot easily set
default value for arguments (Read
this construct is highly useful, Ruby 2 introduced keyword arguments which allows
you to write -
In this challenge, your task is to write a method convert_temp that helps in
temperature conversion. The method will receive a number as an input
(temperature), a named parameter input_scale (scale for input temperature),
and an optional parameter output_scale (output temperature scale, defaults to
Celsius) and return the converted temperature. It should perform
interconversion between Celsius, Fahrenheit and Kelvin scale.