summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-enum-ext/mrblib
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-09-16 08:01:08 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-09-16 10:10:09 +0900
commitd380c7d26f1056c021281d56c2d7110f9d5ce2d1 (patch)
tree94181e46b21ab9008a7d893262105f786251915e /mrbgems/mruby-enum-ext/mrblib
parent57a0132b41920ea14b903113586bf970c8210efa (diff)
downloadmruby-d380c7d26f1056c021281d56c2d7110f9d5ce2d1.tar.gz
mruby-d380c7d26f1056c021281d56c2d7110f9d5ce2d1.zip
Implement `filter_map` from Ruby2.6.
Diffstat (limited to 'mrbgems/mruby-enum-ext/mrblib')
-rw-r--r--mrbgems/mruby-enum-ext/mrblib/enum.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/mrbgems/mruby-enum-ext/mrblib/enum.rb b/mrbgems/mruby-enum-ext/mrblib/enum.rb
index 171737e28..e354a4c5e 100644
--- a/mrbgems/mruby-enum-ext/mrblib/enum.rb
+++ b/mrbgems/mruby-enum-ext/mrblib/enum.rb
@@ -826,5 +826,17 @@ module Enumerable
end
hash.values
end
+
+ def filter_map(&blk)
+ return to_enum(:find_index, val) unless blk
+
+ ary = []
+ self.each do |x|
+ x = blk.call(x)
+ ary.push x if x
+ end
+ ary
+ end
+
alias filter select
end