From: Josh Cheek Date: 2011-09-12T14:13:09+09:00 Subject: Re: Not 2 maps --0016363b7a0c1dd07a04acb795d3 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Sep 11, 2011 at 11:49 PM, botp wrote: > On Mon, Sep 12, 2011 at 12:12 PM, Josh Cheek wrote: > > pre = [[1.1, 2.2, 3.3], [4.1, 5.6, 6.8], [7.1, 8.7, 9.0], [10.0, 11.4, > > 12.6]] > > > > post = Array.new > > pre.each do |inner_array| > > post << [] > > inner_array.each { |num| post.last << num.to_i } > > end > > luv this inject code. hope matz can enhance inject further > > pre.inject([]) do |new_array,inner_array| > new_array + [inner_array.map(&:to_i)] > end > #=> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] > > kind regards -botp > > IDK, I feel like most places #inject is used, #with_object would be a better choice. pre.each.with_object([]) do |inner_array, new_array| new_array << inner_array.map(&:to_i) end --0016363b7a0c1dd07a04acb795d3--