Skip to content

Instantly share code, notes, and snippets.

@watzon
Created May 11, 2019 20:52
Show Gist options
  • Save watzon/ab6e1e6aec4bb00a6a9ae2a998af1abd to your computer and use it in GitHub Desktop.
Save watzon/ab6e1e6aec4bb00a6a9ae2a998af1abd to your computer and use it in GitHub Desktop.
# This example will throw an error at compile time
# allowing you to catch it sooner and fix it
arr = [] of Int32
def sum(arr)
arr.reduce(0) { |acc,i| acc + i }
end
# Works just fine
puts sum [1, 2, 3, 4, 5]
# Throws a compile error
puts sum ["1", 2, 3, 4, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment