# Session arrays, vectors and matrices in Rails... and even ruby

**URL:** <https://www.ruby-forum.com/t/session-arrays-vectors-and-matrices-in-rails-and-even-ruby/153390>\
**Category:** Rails\
**Created:** [November 16, 2008, 5:02am UTC](https://www.ruby-forum.com/t/session-arrays-vectors-and-matrices-in-rails-and-even-ruby/153390 "2008-11-16T05:02:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [November 16, 2008, 5:02am UTC](https://www.ruby-forum.com/t/session-arrays-vectors-and-matrices-in-rails-and-even-ruby/153390/1 "2008-11-16T05:02:29Z")

</div>

Hello…

I just want to make a simple question: is there a way to make arrays,  
vectors and matrices with SESSION VARIABLES on Ruby and Rails? I’m  
making a Rails app and I need to save all the data in session  
variables before saving it to the DB. the catch here is the following  
logic:

element1 has many element2s values stored  
element2 has many element3s values stored

Meaning this:

session[:element1]  
session[:element2][]  
session[:element3][][]

Hope you can answer me this, with a possible solution to this as I  
have little experience to do this on this language and in this  
framework.

Later,

The N.

---

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [November 16, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/session-arrays-vectors-and-matrices-in-rails-and-even-ruby/153390/2 "2008-11-16T13:37:08Z")

</div>

On Nov 16, 4:02 am, The N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello…
> 
> I just want to make a simple question: is there a way to make arrays,  
> vectors and matrices with SESSION VARIABLES on Ruby and Rails? I’m

Yup. Just do it. Construct your array, vector or matrix as you would  
normally and then put it in the session as you would a number or a  
string.

Fred

---

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [November 16, 2008, 4:04pm UTC](https://www.ruby-forum.com/t/session-arrays-vectors-and-matrices-in-rails-and-even-ruby/153390/3 "2008-11-16T16:04:24Z")

</div>

Can the arrays be as many dimensions as I want? Because I took a look  
on how to make the vector and matrices and it looks complicated. No  
offense. Is there and example where I can do such a thing with arrays?

Later…

The N.

---

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [November 16, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/session-arrays-vectors-and-matrices-in-rails-and-even-ruby/153390/4 "2008-11-16T16:15:31Z")

</div>

On Nov 16, 3:03 pm, The N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can the arrays be as many dimensions as I want? Because I took a look  
> on how to make the vector and matrices and it looks complicated. No  
> offense. Is there and example where I can do such a thing with arrays?

Personally I would save the matrix and vector classes for actually  
doing matrix math.  
I think your specification of the problem so far is not concrete  
enough for me to be able to volunteer a solution, but you can  
certainly have something like

x = [[[1,2,3], [4,5,6]],[[7,8,9],[10,11,12]]]  
x[0][1][2] #=\> 6  
At this point this isn’t really a rails question any more - you may  
find more opinions on the ruby-talk list.

Fred
