From: Chris Kottom Date: 2011-03-26T16:14:22+09:00 Subject: Re: critique please --000e0cd53044a0799e049f5d75a0 Content-Type: text/plain; charset=UTF-8 Also the split statements you've used will cause the spaces between the commas and the "item" strings to be preserved in the resulting arrays which is probably not the desired effect. ruby-1.9.2-p0 :001 > globalarray = globalcampaigns.split(",") => ["item1", " item2", " item3", " item4", " item5"] To get around this, pass a regular expression with optional leading and trailing whitespace as the parameter to split. ruby-1.9.2-p0 :002 > globalarray = globalcampaigns.split(/\s*,\s*/) => ["item1", "item2", "item3", "item4", "item5"] On Sat, Mar 26, 2011 at 6:57 AM, Stu wrote: > If you want to save yourself a step you can use the %w{ } > > global_campaigns = %w{ item1 item2 item3 item4 item5 } > > ~Stu > > On Fri, Mar 25, 2011 at 10:12 PM, Charles Oppenheimer > wrote: > > Folks, the first ruby I've written that I actually needed (I shortened > > the actual strings I was comparing, which were very long). So > > thought I'd ask, before I write the next one - is there a more elegant > > way to do this, or conventions that are usually used? > > > > > > Thanks! > > > > globalcampaigns = "item1, item2, item3, item4, item5" > > premiercampaigns = "item1, item2" > > basiccampaigns = "item3, item4" > > > > > > globalarray = globalcampaigns.split(",") > > premarray = premiercampaigns.split(",") > > basicarray = basiccampaigns.split(",") > > > > #globalarray.each {|elt| puts elt} > > > > combo = premarray | basicarray > > diff = globalarray - combo > > > > diff.each {|elt| puts elt} > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > --000e0cd53044a0799e049f5d75a0--