From: dblack@... Date: 2006-03-23T01:24:20+09:00 Subject: Re: why doesn't "to_s" DWIM? Hi -- On Thu, 23 Mar 2006, Chris McMahon wrote: > > How come to_s doesn't work here? > > #################################### > require 'test/unit' > class TOY_CASE > def test_toy_test > > aoa = [[1,2,3],[4,5,6]] > > aoa.each do |arr| > arr.each do |item| > item = item.to_s > end > assert_equal(["1","2","3"],arr) > end > > > end #def > end #class > ########################################## Inside the inner each block, you're just doing a local (re)assignment to "item". There's no connection to the object that used to be in item, except that that object happens to be part of the rhs. You can achieve what you want with this: aaa.each do |arr| arr.map! do |item| item.to_s end end That will go through each inner array and replace the current item with what's in the block (namely, item.to_s). David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black