From: Sean Warburton Date: 2010-01-27T21:05:26+09:00 Subject: Re: Build an array using data from an exisiting array Brian Candler wrote: > > # This converts a single item into its XML request > def process(input) > "The answer is #{input}" > end > > source = ["foo", "bar", "baz"] > > # Option 1: build another array > > dest = source.map { |doc| process(doc) } > puts dest[0] > > # Option 2: build a Hash > > dest = {} > source.each { |doc| dest[doc] = process(doc) } > puts dest["foo"] Thanks everyone for your replies. Brian, this seems like what I'm looking for but can I ask a question. Why if move ... source.each { |doc| dest[doc] = process(doc) } above def process(input) "The answer is #{input}" end rather than below like you have, does it throw the error undefined local variable or method `source' for # (NameError) Thanks -- Posted via http://www.ruby-forum.com/.