# Backwards references in arrays of arrays of

**URL:** <https://www.ruby-forum.com/t/backwards-references-in-arrays-of-arrays-of/72090>\
**Category:** Ruby\
**Created:** [October 14, 2006, 2:09am UTC](https://www.ruby-forum.com/t/backwards-references-in-arrays-of-arrays-of/72090 "2006-10-14T02:09:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f04885/32.png) [@ohad](https://www.ruby-forum.com/u/ohad)\
**Post date:** [October 14, 2006, 2:09am UTC](https://www.ruby-forum.com/t/backwards-references-in-arrays-of-arrays-of/72090/1 "2006-10-14T02:09:10Z")

</div>

I’m creating a scheduling application for my university, the Technion.  
The course data we receive in a file called a REP file, which my  
application parses. Its essential, simplified structure is this:

Faculties (which have names) contain courses  
Courses (which have numbers and names) contain groups  
Groups (which have numbers and lecturer names) contain events  
Events have days, start/end times, and locations

This data I convert once (it takes a while), and then Marshal it. I  
don’t use YAML, though I’d rather do that, because of a unicode bug in  
the stable version. The choice between them is less relevant.

So in my program, the data is stored as an array of Faculty objects,  
which have a courses property which is an array of Course objects, and  
so on - all the way down to events.

Now, I display the rendered schedule using Gecko. I have prepared an  
HTML template for this, for which all I have to add is event lines in  
Javascript, which go something like this:

addEvent(course\_id, day, start, end, desc);

This code is then inserted into the HTML, which goes about the  
rendering. course\_id should be a unique identifier for color-coding.  
desc, which is the actual rendered text, should contain the event’s  
course name & number, group number, lecturer, and location.

Now here’s the kicker - an event doesn’t know all that. It knows its  
day, start/end time, and location. And that it’s an event. It doesn’t  
know what group it’s a part of, what course, nothing.

So the question is - how do I generate the javascript?

Currently, the scheduler returns an array of arrays of groups (an array  
of groups per course). So my options are

- Have the scheduler generate the javascript - let it figure out which  
groups belong to which courses, iterate down to the choices, and  
generate everything

- Store javascript strings within the events during parsing of the REP  
file  
(I don’t like this because if I use YAML later on, I’d like it to be  
redistributable instead of the REP file, and that’s, well, icky)

- Store back-references to the group and course within the event - ruby  
seems to handle this gracefully, with appropriate links in the YAML  
file  
etc. (no infinite recursion). To get a feel for what I mean, try

- …or something else I haven’t thought of. What do you guys think?
