why the lucky stiff
12/21/2004 11:11:00 PM
Dennis Roberts wrote:
> This works! Thanks. What is the difference between each and collect?
> With each it still didn't work, but it did with collect.
The `each' method merely walks an Array (or other Enumerable.) But
`collect' (a.k.a `map') walks the Array, replacing each element with the
result from the block. At the end of `collect', you have a new Array.
So, in the cgi example, you started with an array of:
['one', 'two', 'three']
The `collect' processes each through the `text_field' method and you
wind up with:
["<INPUT NAME=\"one\" SIZE=\"40\" TYPE=\"text\" VALUE=\"one\">",
"<INPUT NAME=\"two\" SIZE=\"40\" TYPE=\"text\" VALUE=\"two\">", "<INPUT
NAME=\"three\" SIZE=\"40\" TYPE=\"text\" VALUE=\"three\">"]
_why