What would be the best way to refactor this :
@busy.each do |b|
title = b.title
@events << {
:id => b.id,
:title => title,
:start => b.busy_start_time(b.start_date,b.start_time),
:end => b.busy_end_time(b.end_date,b.end_time),
:allDay => false,
:recurring => false,
:color => 'black',
}
@events
is initialized as an empty array:
@events = []
And this busy statement is the SECOND of two pushes into @events
.
I think that I can use map here something like :
@events = @events + @busy.map do |b|
stuff
end
Because I don't want to overwrite @events
, I want to add stuff into it.
But what I'm really searching for is a way to store the entire 'each' into a lambda and say something like :
@events += @busy(&:create_busy_hash)
And move all the hash creation into the Busy
class as create_busy_hash
I'm still grasping lambdas and procs