Last active
June 6, 2018 03:37
-
-
Save Rojo/87f148db89e1192523f55be5856da2c1 to your computer and use it in GitHub Desktop.
Muestra de una función que llena ciertas llaves de un `Hash` con valores por defecto cuando están vacias.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEFAULT_VALUES = { temperature: 10, altitude: 1200, pressure: 500 } | |
def fill_default_values(current_values) | |
{}.tap do |values| | |
DEFAULT_VALUES.each_key do | |
|key| values[key] = current_values[key] || DEFAULT_VALUES[key] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment