Skip to content

Instantly share code, notes, and snippets.

@tonilin
tonilin / gist:393986d3588f6c1a00c1
Last active August 29, 2015 14:17
pluck_in_batches.rb
# Reference:
# 1. https://gist.github.com/siannopollo/03d646eb7525f7fce678#file-pluck_in_batches-rb
# 2. https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/batches.rb
class ActiveRecord::Relation
# pluck_in_batches: yields an array of *columns that is at least size
# batch_size to a block.
#
# Special case: if there is only one column selected than each batch
# will yield an array of columns like [:column, :column, ...]