Skip to content

Instantly share code, notes, and snippets.

@bryanwoods
Created February 8, 2017 16:29
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 bryanwoods/c5f49335fbf7fc88635c4251efa6f24f to your computer and use it in GitHub Desktop.
Save bryanwoods/c5f49335fbf7fc88635c4251efa6f24f to your computer and use it in GitHub Desktop.
module Enumerable
def method_missing(meth, *args, &block)
if "#{meth}" =~ /flat_(.*)/
send($1, *args, &block).flatten
else
super
end
end
def respond_to_missing?(meth, include_private = false)
"#{meth}".start_with?("flat_") || super
end
end
p [[1,2,3], [1,2,3]].flat_zip([[4,5,6], [4,5,6]])
p [[1,2,3], [1,2,3]].flat_flat_flat_map { |x| x * 2 }
p [1,2,3].flat_zip([2,4,6])
p [1,2,3, 4].flat_partition(&:even?)
__END__
[1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6]
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
[1, 2, 2, 4, 3, 6]
[2, 4, 1, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment