Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created May 17, 2015 19:25
Show Gist options
  • Save KamilLelonek/080b718f8b767edd77e3 to your computer and use it in GitHub Desktop.
Save KamilLelonek/080b718f8b767edd77e3 to your computer and use it in GitHub Desktop.
Partial function example in Ruby
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