Sha256: 40c1f3c00e793ba1a3ca8f027086fd7236e5255a0700e202a58b1a5d7ad30b7a
Contents?: true
Size: 582 Bytes
Versions: 10
Compression:
Stored size: 582 Bytes
Contents
class Array # Apply a block to hash, and recursively apply that block # to each subhash. # # arr = ["a", ["b", "c", nil], nil] # arr.recursively{|a| a.compact! } # => ["a", ["b", "c"]] # # TODO: Can this be generalized in Enumerbale? def recursively(&block) a = inject([]) do |array, value| if value.is_a?(Array) array << value.recursively(&block) else array << value end array end yield a end # In place form of #recursively. def recursively!(&block) replace(recursively(&block)) end end
Version data entries
10 entries across 10 versions & 2 rubygems