ruby on rails - how to store multidimensional array value -
i have store can set directly follows
self.xxx_bias_store[i][j] = [7,11] where xxx can different names
how set using send. have tried
self.send("#{name}_biases_store[#{i}][#{j}]=".to_sym, [7,11]) but has no effect. interested in how retrieve value i.e.
send("#{name}_biases_store[#{i}][#{j}]".to_sym)
i'm not quite sure why you're trying use send this, , looking @ comment i'm not convinced you're asking right question regardless, here's how works.
the methods you're concerned this:
class array def [](index) # element of array @ index end def []=(index, value) # set element of array @ index value end end thing[5] calls [] method argument 5 - is, sends method [] receiver thing argument 5. similarly, thing[5]=1 calls []= method arguments 5 , 1
a multi-dimensional array array made of other arrays, so...
thing = [[1,2], [3,4]] p thing.send(:[], 1) # => [3,4] p thing.send(:[], 1).send(:[], 0) # => 3 thing.send(:[], 1).send(:[]=, 0, 5) p thing # => [[1,2], [5,4]]
Comments
Post a Comment