Created
November 19, 2012 17:02
-
-
Save david/4111893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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