Skip to content

Instantly share code, notes, and snippets.

@RBdevelop
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RBdevelop/1059b866ce066e308d4b to your computer and use it in GitHub Desktop.
Save RBdevelop/1059b866ce066e308d4b to your computer and use it in GitHub Desktop.
explain local translator method optimize
def optimize(hsh) ## defining method optimize with var(hsh)
hsh.reduce({}) do |new_hsh, (k,v)| ## reduce the hsh parameter into a new object with parameters (k,v)
new_hsh[k.to_sym] = v.kind_of?(Hash) ? optimize(v) : v
#ok new object (new_hsh) has a k parameter being converted to a symbol.
# the symbol is then confirmed to be a Hash . If true then defined to be parameter v.
new_hsh
##return the new_hsh
end
end
## I get this . Its method is a translator for localization purpose . It can be used to take incoming data translate it into local language then commits to database.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment