Named Matrix like ArrayFields

I’m looking for a named matrix that acts like arrayfields so you can
get and set cells based on a name and/or an index. This is array
fields <
arrayfields-4.7.0/> :

require ‘arrayfields’
=> true

x =,:b,:c,:d)
=> [:b, :d]

=> :b

=> :b

=> :b

I basically want that but in two dimensions.

Something like:

x =
x.xs = %w(a b c d) # the names of the x axis
x.ys = %w(e f g h) # the names of the y axis

So that x[:a][:f] is the same as x[0][1] for getting and setting. Also
have some dumping mechanism to get an array of arrays or arrays of
hashes or even csv or some other 2D dump.

I don’t think this is too tough to write especially with arrayfields
but was wondering if anyone has done it yet.



Maybe take a look at Struct.

x =,:b,:c)
y =,:e,:f)
var =,1,2),,11,12),,21,22))

p var[:c][:e]
p var[2][1]
p var[‘c’][“e”]

var[2][:e] = 77
p var[:c][:e]


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs