Skip to content

Instantly share code, notes, and snippets.

@buffpojken
Created June 30, 2015 21:35
Show Gist options
  • Save buffpojken/73bd77117bdacfaeda61 to your computer and use it in GitHub Desktop.
Save buffpojken/73bd77117bdacfaeda61 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