Skip to content

Instantly share code, notes, and snippets.

@Rojo
Last active June 6, 2018 03:37
Show Gist options
  • Save Rojo/87f148db89e1192523f55be5856da2c1 to your computer and use it in GitHub Desktop.
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.
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