Created
September 7, 2015 16:58
-
-
Save KamilLelonek/a5ae82e8786e34ab43b6 to your computer and use it in GitHub Desktop.
For a given integer return a result of dividing 8 by that number with handling 0.
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
Contract Num, Func[Num => Any], Proc => Any | |
def eight_divide_by(number, success_action, failure_action) | |
case number | |
# ... | |
when 4 then success_action[2] | |
when 2 then success_action[4] | |
when 1 then success_action[8] | |
when 0 then failure_action.call | |
end | |
end | |
success_action = lambda { |value| "Got #{value}" } | |
failure_action = lambda { "You probably wanted to divide by 0, didn't you?" } | |
eight_divide_by(1, success_action, failure_action) # => Got 8 | |
eight_divide_by(0, success_action, failure_action) # => You probably wanted to divide by 0, didn't you? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment