Skip to content

Instantly share code, notes, and snippets.

@mayth
Created April 23, 2018 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayth/fd1432c3f8034cbc9b8222fe9f7175d7 to your computer and use it in GitHub Desktop.
Save mayth/fd1432c3f8034cbc9b8222fe9f7175d7 to your computer and use it in GitHub Desktop.
オープンクラス最高! 一番好きなクラスです!
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