I would like to add a method to all collections for a specific model. Let\'s say I want to add the method my_complicated_averaging_method
to the WeatherData collect
On Rails >= 4 you can to use where(nil)
inplace of scoped
class Foo < ActiveRecord::Base
def self.bar
where(nil).pluck(:id)
end
end
Foo.where(id: [1, 2, 3]).order(:id).bar
And further, you can use #scope
, for example:
class Foo < ActiveRecord::Base
scope :bar, -> {where(nil).pluck(:id)}
end
Finally, You can write code like Foo.all.bar