Is there a Ruby equivalent for Perl Data :: Rmap?

Perl Data :: Rmap allows you to recursively evaluate BLOCKs over a list of data structures (by setting $ _ locally for each item) and return a list of the results of those evaluations. $ _ can be used to modify items.

This is useful for iterating over things like nested hashes or hash array hierarchies, etc.

+1


source to share


2 answers


Ruby Enumerable

does whatever you want I think. "... and return a list of the results of those evaluations" means whatever you want Enumerable#map

. My first jump would be something like this:



[ {...}, {...}, {...}, ... ].map do |hash|
  hash.something
  do_other_stuff_with(hash)
  hash                  # important to have as last line b/c of how #map works
end

      

+2


source


Without going into details, I'm not sure if you need a Ruby module. Iterators and blocks should do what you want.



+1


source







All Articles