Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Last active December 10, 2015 10:19
Show Gist options
  • Save LolWalid/94e8d6b731be8369db55 to your computer and use it in GitHub Desktop.
Save LolWalid/94e8d6b731be8369db55 to your computer and use it in GitHub Desktop.
Class methods apply to collection - Ruby
class MyModel < ActiveRecord::Base
scope :custom_scope, -> { where.not(id: [1, 2, 3]) } # id not in (1, 2, 3) <=> id != 1 and id != 2 and id != 3
def self.class_method
all.each { |x| puts x }
end
def to_s
'Hey'
end
end
MyModel.custom_scope.class_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment