Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@david
Created November 19, 2012 17:02
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 david/4111893 to your computer and use it in GitHub Desktop.
Save david/4111893 to your computer and use it in GitHub Desktop.
module Assertions
def demand(&block)
block.call or raise ConditionFailed
end
def promise(&block)
tap { |o| yield o or raise ConditionFailed }
end
def refuse(&block)
! block.call or raise ConditionFailed
end
class ConditionFailed < Exception
end
end
def block(vendor)
demand { vendor.present? }
blocked_vendors_x.
block(vendor).
promise { blocking?(vendor) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment