Stephen White <steve / deaf.org> writes: | 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) That's not quite the same. In the first case, ones_names[0] = '' and ones_names = 'one'. In the second case, ones_names[0] = 'one' and ones_names[1] = 'two'. (If I didn't need an empty initial element, I would have used %w.) | > > ['', 'thousand', 'million', 'billion', 'trillion'].map { |gstr| | > > (num, group) = num.divmod (1000) | | What's the difference between map and each here? 'each' calls the supplied block once for each element, and returns the original array. 'map' calls the supplied block once for each element, and returns a new array composed of the block's results. -- http://www.dfan.org