Created
March 30, 2014 07:15
-
-
Save Chandler/9868940 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
class Try | |
attr_accessor :error, :success | |
#shortcuts | |
def self.error(error) | |
self.new({error: error}) | |
end | |
def self.success(success) | |
self.new({success: success}) | |
end | |
def initialize(options) | |
if options[:error] && options[:success] | |
raise "Try can only be initialized with error or success not both" | |
elsif options[:error] | |
@error = options[:error] | |
elsif options[:success] | |
@success = options[:success] | |
else | |
raise "Try must be initialized with either error or success" | |
end | |
end | |
def error? | |
!!@error | |
end | |
def success? | |
!!@success | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment