# Adding to a struct

**URL:** <https://www.ruby-forum.com/t/adding-to-a-struct/92502>\
**Category:** Rails\
**Created:** [April 20, 2007, 2:03am UTC](https://www.ruby-forum.com/t/adding-to-a-struct/92502 "2007-04-20T02:03:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@mick](https://www.ruby-forum.com/u/mick)\
**Post date:** [April 20, 2007, 2:03am UTC](https://www.ruby-forum.com/t/adding-to-a-struct/92502/1 "2007-04-20T02:03:40Z")

</div>

Hi guys,

A little struct question:

@events = Event.get\_filtered\_events(@search\_term)

returns a struct, but I want to call another query within a loop:

for event\_type in @event\_types  
get\_filtered\_events\_by\_type(event\_type.id)  
end

and I want to add the results to the @events struct above, how do I do  
this?

Cheers

Mick

---

<div class="post-metadata">

**Author:** ![mick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@mick](https://www.ruby-forum.com/u/mick)\
**Post date:** [April 20, 2007, 3:04am UTC](https://www.ruby-forum.com/t/adding-to-a-struct/92502/2 "2007-04-20T03:04:54Z")

</div>

Mick wrote:

> Hi guys,
> 
> A little struct question:
> 
> @events = Event.get\_filtered\_events(@search\_term)
> 
> returns a struct, but I want to call another query within a loop:
> 
> for event\_type in @event\_types  
> get\_filtered\_events\_by\_type(event\_type.id)  
> end
> 
> and I want to add the results to the @events struct above, how do I do  
> this?
> 
> Cheers
> 
> Mick

What do you mean by “struct” exactly? Do you mean a Struct described  
here? [class Struct - RDoc Documentation](http://www.ruby-doc.org/core/classes/Struct.html)

It would make the most sense to me if Event.get\_filtered\_events returned  
an array of events. If it did then you could simply append events to  
the end of the array in your loop with:

@event\_types.each do |event\_type|  
@events += get\_filtered\_events\_by\_type(event\_type.id)  
end
