From: Reuben Grinberg Date: 2007-04-14T00:20:06+09:00 Subject: Re: conditional statements within test method parameters? aidy.lewis@googlemail.com wrote: > hi, > > I have a test method that writes some xml. The second parameter is > optional, the first parameter is boolean. > > > test_results((assert(REMEMBER_ME.isSet?)), *msg) > > > Would it be possible to embed a conditional statement between these > parameters > > Something like: > > > test_results((assert(REMEMBER_ME.isSet?)), unless 'the object is not > set') ? > > > cheers > > aidy > Yes, but it's not necessarily pretty: def test(one, *two) puts one two.each { |t| puts t} end irb> test("bob", "jack", "andy") bob jack andy irb> test("bob") bob irb> some_condition = false irb> test("bob", some_condition ? ["jack", "andy"] : []) bob irb> The "optional" argument is actually a list, so passing in the empty list for it is the same thing as not passing it in. Cheers, Reuben