Skip to content

Instantly share code, notes, and snippets.

@buffpojken
Last active August 29, 2015 14:24
Show Gist options
  • Save buffpojken/cd3bdd8a98e1ec89ef0a to your computer and use it in GitHub Desktop.
Save buffpojken/cd3bdd8a98e1ec89ef0a to your computer and use it in GitHub Desktop.
class Array
alias_method :_each, :each
def each(&block)
cpy = Array.new(self)
cpy.pop
cpy._each{|n| block.call(n) }
end
end
a = [1,2,3]
a.each do |num|
puts num # => 1,2
end
puts a.inspect # => puts [1, 2, 3]
puts a.reduce(:+) # => puts 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment