I'm trying to understand how the format option works in the groupdate gem.
The readme explains that format takes a string that is passed to strftime or a proc (here).
I'm having trouble understanding the proc part of this.
A simple example, if User.group_by_month(:created_at).count.keys returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] (i.e., months of the year), how would I do a simple transformation of these keys, say key * 2?
Looking at the source, format appears to be expecting a method
if options[:format].respond_to?(:call)
options[:format]
end
So I would have expected to be able to do something like User.group_by_month(:created_at, format: 'Proc.new { |d| d * 2 }')....
But this returns only Proc.new { |d| d * 2} as a string.
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire