Лазар обнови решението на 18.10.2016 21:59 (преди около 8 години)
+def integer?(x)
+ x.to_i.to_s == x
+end
+
+def parse(current, x)
+ if integer?(x)
+ x = x.to_i
+ elsif current[x] == nil
+ x = x.to_sym
+ end
+ x
+end
+
+class Hash
+ def fetch_deep(address)
+ address_arr = address.split(".")
+ current = self
+ address_arr.each do |x|
+ current = current[parse(self, x)]
+ end
+ current
+ end
+end
+
+class Hash
+ def reshape(shape)
+ current = self
+ shape.each do |key, value|
+ if value.is_a? Hash
+ reshape(value)
+ else
+ shape[key] = current.fetch_deep(value)
+ end
+ end
+ end
+end
+
+class Array
+ def reshape(shape)
+ arr = []
+ current = self
+ temp = shape.clone
+ current.map do |x|
+ arr.push(x.reshape(temp))
+ temp = shape.clone
+ end
+ arr
+ end
+end