Created
April 23, 2018 17:30
-
-
Save mayth/fd1432c3f8034cbc9b8222fe9f7175d7 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 | |
def scan(init, &op) | |
res = Array.new(self.length) | |
m = init | |
self.each_with_index do |x, i| | |
acc = op.call(m, x) | |
res[i] = acc | |
end | |
res | |
end | |
end | |
p [1, 3, 5, 7, 9].scan(0) { |a, b| a + b } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment