Last active
August 29, 2015 14:26
-
-
Save RBdevelop/1059b866ce066e308d4b to your computer and use it in GitHub Desktop.
explain local translator method optimize
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
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