From: Terry Michaels Date: 2010-09-09T13:16:05+09:00 Subject: Re: Receiving array naturally? Clifford Heath wrote: > Terry Michaels wrote: >> def process_data(*strings) >> ... >> end >> >> That works with the comma-separated list, because the list gets combined >> into one array ("strings"), but if I pass in an array object, that array >> object is not split up, but rather becomes one (Array object) element of >> the "strings" array. >> >> is there something else I'm overlooking? > > You've overlooked the simplest way: > > def process_data(*strings) > Array(strings).each do |s| > ... > end > end That doesn't work, because an array passed it gets treated like simply an element of the "strings" array: def process_data(*strings) Array(strings).each do |s| print s.class.to_s + " " + s.to_s + " " + "\n" end end process_data("a", "b", "c") process_data(["a", "b", "c"]) # Produces: # # String a # String b # String c # Array abc -- Posted via http://www.ruby-forum.com/.