Skip to content

Instantly share code, notes, and snippets.

@aereal
Created March 10, 2011 21:59
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 aereal/865017 to your computer and use it in GitHub Desktop.
Save aereal/865017 to your computer and use it in GitHub Desktop.
class Promise
def initialize(_type, &block)
@type = _type
@converter = block_given? ? block : proc {|value| @type.new(value) }
end
def validate(val)
@type === val or raise ArgumentError
end
def <=(val)
validate(val) and @converter[val]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment