We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Ruby - Methods - Keyword Arguments
Ruby - Methods - Keyword Arguments
Sort by
recency
|
104 Discussions
|
Please Login in order to post a comment
def convert_temp(temp, input_scale="celsius", output_scale="celsius"): scales = { "celsius": (1, 0), "kelvin": (1, 273.15), "fahrenheit": (1.8, 32) }
end
"Ruby - Methods - Keyword Arguments" is a great topic because it touches on one of Ruby’s most readable and flexible features. Keyword arguments make method calls more expressive and self-documenting, which is especially helpful in larger or more complex codebases. Gold Site 365
I'm with a problem with my code, because it works when I run it on VScode, but when I try on HackerRank, it don't works
def convert_temp(temperature,input_scale:,output_scale:'celsius') if input_scale=='celsius' if output_scale=='kelvin'
elsif input_scale=='kelvin'
elsif input_scale=='fahrenheit'
end end
puts convert_temp(0, input_scale: 'celsius', output_scale: 'kelvin')
Using Ruby Symbols and Lambdas to get a readable table of conversions.