Ruby on Rails Sunday, January 30, 2011

> Are you under the assumption that
>
> parent = Event.new
>
> rolling_event_one.parent = parent
> rolling_event_two.parent = parent
> rolling_event_three.parent = parent
>
> creates 3 copies of parents? It doesn't (unless you've written parent=
> to store a copy of parent)
>
> Fred

Hi Fred,

So, essentially on creation of a RollingEvent I'd be passing in a
reference to the parent Event?

Something like:

@events.each |parent_event| do
date = parent_event.start_date
while date <= parent_event.end_date
allevents << RollingEvent.new(parent_event, date)
date += days_between_repeats
end
end

class RollingEvent{
def initialize(parent_event, date)
@parent_event = parent_event
@date = date
end

Would I have to make a method for every single data member like so:

def amount
@parent_event.amount
end
def title
@parent_event.title
end
end

??

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment