aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-08-06 17:20:02 +0800
committerXu Cheng2015-08-06 22:33:46 +0800
commit7c72b0c68a8ee4dfe3d5b5b922d21519c584a3bf (patch)
treef6150695b3416cff4beeddc5ae4f90884b713ebd /Library
parentae0e270727cdd38d0c8b4ed2062f944a8596c6ea (diff)
downloadbrew-7c72b0c68a8ee4dfe3d5b5b922d21519c584a3bf.tar.bz2
backport flat_map for Ruby 1.8
Code is copied from https://github.com/marcandre/backports/blob/master/lib/backports/1.9.2/enumerable/flat_map.rb (MIT License by Marc-Andre Lafortune) Closes Homebrew/homebrew#42543. Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/extend/enumerable.rb11
-rw-r--r--Library/Homebrew/global.rb1
2 files changed, 12 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/enumerable.rb b/Library/Homebrew/extend/enumerable.rb
new file mode 100644
index 000000000..fededbfca
--- /dev/null
+++ b/Library/Homebrew/extend/enumerable.rb
@@ -0,0 +1,11 @@
+module Enumerable
+ def flat_map
+ return to_enum(:flat_map) unless block_given?
+ r = []
+ each do |*args|
+ result = yield(*args)
+ result.respond_to?(:to_ary) ? r.concat(result) : r.push(result)
+ end
+ r
+ end unless method_defined?(:flat_map)
+end
diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb
index 5a809ab6f..4ab84941c 100644
--- a/Library/Homebrew/global.rb
+++ b/Library/Homebrew/global.rb
@@ -3,6 +3,7 @@ require "extend/fileutils"
require "extend/pathname"
require "extend/ARGV"
require "extend/string"
+require "extend/enumerable"
require "os"
require "utils"
require "exceptions"