Skip to content

Instantly share code, notes, and snippets.

@kwstannard
Created October 28, 2015 19:36
Show Gist options
  • Save kwstannard/55cd78ea3fd17c74076e to your computer and use it in GitHub Desktop.
Save kwstannard/55cd78ea3fd17c74076e to your computer and use it in GitHub Desktop.
# boring var technique
x = nil
[1,2,3,4].each do |y|
if x
puts x + y
end
x = y
end
# cool inject technique
[1,2,3,4].inject do |x, y|
puts x + y
y
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment