Recursively iterate over the Array’s elements. If an element is an Array or responds to # then it will be itereated over as well.
# File lib/core/facets/array/recursive.rb, line 44 44: def each(&block) 45: if block_given? 46: @enum.each do |e| 47: if Array === e || e.respond_to?(:to_ary) 48: e.to_ary.recursive.each(&block) 49: else 50: block.call(e) 51: end 52: end 53: else 54: to_enum(:each) 55: end 56: end
Returns a new array created by traversing the array and its sub-arrays, executing the given block on the elements.
h = ["A", "B", ["X", "Y"]] g = h.recursive.map{ |e| e.downcase } g = ["a", "b", ["x", "y"]]
CREDIT: Trans
# File lib/core/facets/array/recursive.rb, line 69 69: def map(&block) 70: if block_given? 71: @enum.map do |e| 72: if Array === e || e.respond_to?(:to_ary) 73: e.to_ary.recursive.map(&block) 74: else 75: block.call(e) 76: end 77: end 78: else 79: to_enum(:map) 80: end 81: end
Like #, but will change the array in place.
# File lib/core/facets/array/recursive.rb, line 85 85: def map!(&block) 86: replace(map(&block)) 87: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.