From: matz@... Date: 2014-02-23T17:05:34+00:00 Subject: [ruby-core:61032] [ruby-trunk - Feature #9552] [Feedback] Module map! Issue #9552 has been updated by Yukihiro Matsumoto. Status changed from Open to Feedback I am not sure I understand your intention fully, but at least map! reminds us too much of enumerators. I don't think there's a chance to add map! to module. Try another name. Maybe some kind of method (or function) combination natation can help you. Matz. ---------------------------------------- Feature #9552: Module map! https://bugs.ruby-lang.org/issues/9552#change-45437 * Author: Boris Stitnicky * Status: Feedback * Priority: Normal * Assignee: * Category: * Target version: ---------------------------------------- I would like to beg for `map!` directive in `Module`. I can imitate it with this code: ```ruby class Module def map! **hash, &block hash.each_pair { |mapped_method_symbol, original_method_symbol| define_method mapped_method_symbol do |*args, &b| block.( send original_method_symbol, *args, &b ) end } end end ``` And then ```ruby class Foo; attr_accessor :name end class Bar; attr_accessor :name end class Baz; attr_accessor :name end class FooBarBazCollection < Array def foos; select { |e| e.is_a? Place } end def bars; select { |e| e.is_a? Transition } end def bazs; select { |e| e.is_a? Arc } end map! fn: :foos, barn: :bars, bazn: :bazs do |retval| retval.map &:name end end ``` I solemnly declare that I have encountered this pattern in my work on Petri net gem sufficiently many times to warrant this meta approach. The above method `#map!` is not perfect, because it makes the "mapped" methods more omnivorous -- accepting even such sets of arguments, for which the originals returned `ArgumentError`. I do not know how to solve this without asking for a core-level solution. -- http://bugs.ruby-lang.org/