Home > Blockchain >  How to chain methods inside the ruby group_by arguments
How to chain methods inside the ruby group_by arguments

Time:05-11

I have a list of slot time instances called slots, with a start time column.

I want to group these slots by start_time.to_date but i cant find the syntax to chain these methods together.

The error i am currently getting by running the below code is undefined method to_date for :start_time:Symbol

slots.group_by(&:start_time.to_date)

CodePudding user response:

You will need to define the group_by block

slots.group_by {|slot| slot.start_time.to_date }
  • Related