Skip to content

Instantly share code, notes, and snippets.

@chrisarcand
Created December 7, 2021 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisarcand/1227578c97415db585600228254813e8 to your computer and use it in GitHub Desktop.
Save chrisarcand/1227578c97415db585600228254813e8 to your computer and use it in GitHub Desktop.
class ApplicationRecord
def in_scope?(sym)
self.class.public_send(sym).exists?(id)
end
end
class Location < ApplicationRecord
scope :editable -> {...}
# OR
def in_editable?
self.class.editable.exists?(id)
end
end
# loc = Location.last
#
# loc.in_scope?(:editable)
# loc.in_editable?
# Location.editable.exists?(loc.id) # FWIW though I'd just use this, without any of this extra stuff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment