Created
August 3, 2016 16:32
-
-
Save hackervera/4948e5857b65714116532129a4fe9f8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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