Skip to content

Instantly share code, notes, and snippets.

@liaden
Last active September 25, 2015 22:16
Show Gist options
  • Save liaden/4472ef8c0e726719d58b to your computer and use it in GitHub Desktop.
Save liaden/4472ef8c0e726719d58b to your computer and use it in GitHub Desktop.
Maybe, just maybe it will have a value
class Maybe
def initialize(item, &block)
@item = item
@block = block || proc { |item| !item.nil? }
end
def just
yield(@item) if @block.call(@item)
end
end
Maybe.new(5).just { |x| puts x }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment