Skip to content

Instantly share code, notes, and snippets.

@sneakin
Created May 8, 2010 04:41
Show Gist options
  • Save sneakin/394342 to your computer and use it in GitHub Desktop.
Save sneakin/394342 to your computer and use it in GitHub Desktop.
class Doc
class Base
def read; end
def destroy!; end
end
class File < Base
# operates on a file
end
class DestroyedDoc < Base
# raises errors
end
class Proxy < Base
def initialize(doc)
@doc = doc
end
def destroy!
@doc.destroy!
@doc = Doc::DestroyedDoc.new(path)
end
def read
@doc.read
end
end
def self.open(path)
Doc::Proxy.new(Doc::File.new(path))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment