I think your problem is that Array defines its own collect
method rather than using Enumerable's:
collect {|item| block } → new_ary
map {|item| block } → new_ary
collect → an_enumerator
map → an_enumeratorInvokes block once for each element of
self
. Creates a new array containing the values returned by the block. See alsoEnumerable#collect
.
So you can monkey patch Enumerable#collect
all you want but Array
won't care because it doesn't use Enumerable#collect
. You'll have better luck if you monkey patch Array#collect
:
class Array
def collect
#...
end
end
You'll want to patch Array#map
as well or just patch map
and let the alias take care of collect
.
Note that Array#map
is implemented in C so the C part had nothing to do with your problem.