Skip to content

Instantly share code, notes, and snippets.

@sanrodari
Forked from anonymous/ruby_fiddle.rb
Created July 3, 2012 02:23
Show Gist options
  • Save sanrodari/3037131 to your computer and use it in GitHub Desktop.
Save sanrodari/3037131 to your computer and use it in GitHub Desktop.
Unwrap Props
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