Skip to content

Instantly share code, notes, and snippets.

@etagwerker
Last active July 5, 2016 18:55
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 etagwerker/8760a38692461caca67f9cd27c89ce75 to your computer and use it in GitHub Desktop.
Save etagwerker/8760a38692461caca67f9cd27c89ce75 to your computer and use it in GitHub Desktop.
null_object.rb
class Seller
belongs_to :user
def can_add_products?
products.count < seller.products_limit
end
def seller
if is_sysadmin?
NullSeller.new
else
super
end
end
end
class User
has_one :seller
end
# Usage
if user.seller.can_add_products?
puts "Can add products"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment