Skip to content

Instantly share code, notes, and snippets.

@hackervera
Created August 3, 2016 16:32
Show Gist options
  • Save hackervera/4948e5857b65714116532129a4fe9f8b to your computer and use it in GitHub Desktop.
Save hackervera/4948e5857b65714116532129a4fe9f8b to your computer and use it in GitHub Desktop.
Iaction = Struct.new(:value, :status)
Reader = Struct.new(:filename) do
def read
Iaction.new File.read(filename), :ok
rescue => e
Iaction.new e, :err
end
end
def readfile(filename)
reader = Reader.new(filename).read
case reader.status
when :ok
reader.value
when :err
#error handling logic
else
#something really bad happened
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment