Clarification needed for simple_calendar sort_by method
Hi Chris,
I've seen simple_calendar
ruby gem and i stuck at sort_by method (calendar.rb)
def events_for_date(current_date)
if events.any? && events.first.respond_to?(:simple_calendar_start_time)
events.select do |e|
current_date == e.send(:simple_calendar_start_time).in_time_zone(@timezone).to_date
end.sort_by(&:simple_calendar_start_time)
else
events
end
end
May be its stupid question or i dont know and i also tried tracing using pry for this method but i cannot understand how here sort_by works ..! Do you mind give me some idea on this how events
are sorting here.
The &:symbol
syntax basically just turns a method name into a block to call. What it is doing is sorting the array of events by the simple_calendar_start_time
column. First we select out the ones for the day in the select block and then we sort by the start time so that all the events are filtered and in order.
That make more sense?