Created
May 17, 2015 19:25
-
-
Save KamilLelonek/080b718f8b767edd77e3 to your computer and use it in GitHub Desktop.
Partial function example in Ruby
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
def divide(dividend, divisor) | |
dividend / divisor | |
rescue ZeroDivisionError | |
p $!.message | |
end | |
def average(*values) | |
raise ArgumentError.new('No values given') if values.empty? | |
raise ArgumentError.new('Not all values are numbers') unless values.all? { |value| value.is_a? Numeric } | |
values.reduce(:+) / values.length | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment