From: Colin Bartlett Date: 2010-09-03T02:35:28+09:00 Subject: Re: selecting a variable number of individual items --001485f7965a5138ee048f4a3ddf Content-Type: text/plain; charset=ISO-8859-1 On Thu, Sep 2, 2010 at 5:05 PM, Joe Pizzanley wrote: > I have a select field where I want to select a variable number of > individual items. How would I set up a def to handle this? > > for example, one time I would select apples. Another time I would select > pears, plums and grapes. > I think that the code line: $ie.select_list(:name, > 'FRUITS').select_value('plums') would vary in value and also in times > called, but that's as far as I can figure out. > > (I can't call myself a newbie because I've been studying Ruby a long time. I'm a bit hesitant to suggest this because you've been studying Ruby a long time, and because I don't think I understand sufficiently what you want to do. Do you want to do something like these: class VarArgsExample def select_example_using_variable_args( *args ) # now process the arguments to the method, for example args.each do |v| # do something with v end # maybe more processing end def select_example_using_array_arg( ary ) # a similar idea works for a hash argument ary = [ary] unless ary.kind_of?( Array ) # now process the array values, for example ary.each do |v| # do something with v end # maybe more processing end end obj = VarArgsExample.new obj.select_example_using_variable_args( 'apples' ) obj.select_example_using_variable_args( 'pears', 'plums', 'grapes' ) obj.select_example_using_array_arg( 'apples' ) obj.select_example_using_array_arg( ['apples'] ) obj.select_example_using_array_arg( ['pears', 'plums', 'grapes'] ) --001485f7965a5138ee048f4a3ddf--