Answer the question
In order to leave comments, you need to log in
How to set the value of a hash element from an array of keys?
Available
hash = {:a => {:b => [{:c => old_val}]}}
keys = [:a, :b, 0, :c]
new_val = 10
Answer the question
In order to leave comments, you need to log in
in general, the solution was found. thanks to all )
a = {:a => {:b => [{:c => 1}]}}
b = [:a, :b, 0, :c]
d = b.pop
b.inject(a) {|s,k| s[k]}[d] = 20
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question