From: Ron Jeffries Date: 2002-02-26T20:25:28+09:00 Subject: Re: Question with for loop On Tue, 26 Feb 2002 07:03:29 GMT, shreeve@s2s.org (Steve Shreeve) wrote: >b.rpc('ORWU TOOLMENU',[nil]) >b.rpc('ORWU HASKEY',['XUPROGMODE']) >b.rpc('ORQQPX NEW REMINDERS ACTIVE') >['O RX', 'I RX', 'UD RX', 'IV RX'].each { |val| b.rpc("ORWORDG IEN", [val]) } >b.rpc('ORWU DT', ['NOW']) >b.rpc('ORWCH LOADAL') > >Notice how the third to last line is sort of "doing it's own thing". It would >be nice have all these lines "look the same". Something like this would work: For another angle on this question, what we have here is a "code smell", where not all the code is at the same level of abstraction. It's generally considered to be a good idea to fix that. When I have a bunch of nearly-duplicate code like the above, I try to remove the duplication.Here the duplication isn't just "b.rpc", it's that plus "paren, a string, maybe comma another string, paren". So I think of setting up the parameters as a data table and looping over the whole thing ... One approach might be something like this. (I've put in 'puts' and #{} to see what's up. The real code would be similar but not identical commands = <