I would like to sort my games by game_date, but sometimes the game_date may be null, and I will get an exception: undefined method `to_datetime’ for nil:NilClass
@games = @teams.reduce([]) { |memo, team| memo + team.games }.sort_by(&:game_date)
Any good way of doing this?
If you just want to drop entries without date, simplest solution –
adding nils at the end can be done with
If you happen to know the range of possible dates, you can be fine with something like
BTW, reduce in your statement can be changed to (IMHO) more clear