-
-
Save sanrodari/3037131 to your computer and use it in GitHub Desktop.
Unwrap Props
This file contains hidden or 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
property = [:algo, :face, :lo] | |
puts suffix_property_id = | |
property.inject { |memo, prop| "#{memo}_#{prop}"} | |
model = {algo: {otro: 'cantelas', face: {lo: 'lu'}}} | |
def unwrap model, property, index = 0 | |
if index < property.length - 1 | |
puts property[index] | |
next_model = model[property[index]] | |
unwrap next_model, property, index + 1 | |
else | |
model[property[index]] | |
end | |
end | |
puts(unwrap model, property) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment