Елеонора обнови решението на 23.10.2016 19:08 (преди около 9 години)
+class Hash
+  def fetch_deep(path)
+    path_array = path.split('.')
+
+    find_path(path_array, self)
+  end
+end
+
+def find_path(path_array, object)
+  return object if path_array.empty? || !object
+
+  if object.class == Array
+    find_path(path_array.drop(1), object[path_array[0].to_i])
+  else
+    find_path(path_array.drop(1), object[path_array[0].to_sym]) ||
+    find_path(path_array.drop(1), object[path_array[0]])
+  end
+end
+
+class Hash
+  def reshape(shape)
+    shape.each_key do |key|
+      shape[key] = if shape[key].class == String
+                     fetch_deep(shape[key])
+                   else
+                     reshape(shape[key])
+                   end
+    end
+    shape
+  end
+end
+
+class Array
+  def reshape(shape)
+    each.map { |n| n.reshape(shape.clone) }
+  end
+end
