On Thu, 21 Dec 2000, Stephen White wrote: > On Thu, 21 Dec 2000, Kevin Smith wrote: > > > > ones_names = '.one.two.three.four.five.six.seven.eight.nine.ten. > > > eleven.twelve.thirteen.fourteen.fifteen.sixteen.seventeen. > > > eighteen.nineteen'.split('.') > > > > Nice way to set up an array of strings. I'll borrow it. It beats ['', > > 'one', 'two'...]. > > Here's another way: > > ones_names = %w(one two three four five six seven eight nine ten > eleven twelve thirteen fourteen fifteen sixteen > seventeeen eighteen nineteen) > The only thing is... you need a null first element. So you'd have to do: ones_names = %w{ ... } .unshift '' or equivalent. (See my earlier benchmarking of these two techniques.) > > > ['', 'thousand', 'million', 'billion', 'trillion'].map { |gstr| > > > (num, group) = num.divmod (1000) > > What's the difference between map and each here? Same as everywhere :-) map returns a new array consisting of the elements of the input array with whatever the block does done to them. each returns the original array. So if everything you want to do is inside the block, use each. If you want to save the results, or pass them along to another array operator, or whatever, then use map. irb(main):001:0> a = [1,2,3] [1, 2, 3] irb(main):002:0> a.each do |e| p e * 6 end 6 12 18 [1, 2, 3] irb(main):003:0> b = a.map do |e| e * 6 end [6, 12, 18] David -- David Alan Black home: dblack / candle.superlink.net work: blackdav / shu.edu Web: http://pirate.shu.edu/~blackdav