Created
June 30, 2015 21:35
-
-
Save buffpojken/73bd77117bdacfaeda61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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