Skip to content

Instantly share code, notes, and snippets.

@pushcx
Forked from krainboltgreene/pattern.rb
Last active August 29, 2015 14:24
Show Gist options
  • Save pushcx/7a518425daf0f7b1907b to your computer and use it in GitHub Desktop.
Save pushcx/7a518425daf0f7b1907b to your computer and use it in GitHub Desktop.
entity = Node.new(id: id)
case
when not enity.exists? then fail("Entity doesn't exist")
when not entity.file? then fail("Entity wasn't a file")
when not entity.writable? then fail("Entity wasn't writable")
else entity.write(data)
end
entity = Node.new(id: id)
if enity.exists? && entity.file? && entity.writable?
entity.write(data)
else
fail("Entity doesn't exist") unless entity.exists?
fail("Entity wasn't a file") unless entity.file?
fail("Entity wasn't writable") unless entity.writable?
end
entity = Node.new(id: id)
class Node
def write(data)
fail("Entity doesn't exist") unless exists?
fail("Entity wasn't a file") unless file?
fail("Entity wasn't writable") unless writable?
# usual write work
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment