Skip to content

Instantly share code, notes, and snippets.

@aponsin
Created March 1, 2012 10:53
Show Gist options
  • Save aponsin/1949074 to your computer and use it in GitHub Desktop.
Save aponsin/1949074 to your computer and use it in GitHub Desktop.
def seek_and_replace(array_of_keys, new_value)
last_level = self
sought_value = nil
array_of_keys.each_with_index do |_key_, _idx_|
if last_level.is_a?(Hash) && last_level.has_key?(_key_)
if _idx_ + 1 == array_of_keys.count
last_level[_key_] = new_value
else
last_level = last_level[_key_]
end
else
break
end
end
self
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment