From: RichardOnRails Date: 2010-12-23T22:55:21+09:00 Subject: Re: How to DRY code to prompt for parameters On Dec 23, 12:00 am, "Abinoam Jr." wrote: > http://www.pastie.org/1399777 > > 1) I don't think you need an Array of Hash. Just a Hash. > 2) I used "eval" to do what you want > > Was it something like this what you wanted? > > Abinoam Jr. > > On Thu, Dec 23, 2010 at 1:40 AM, Ryan Davis wrote: > > > On Dec 22, 2010, at 20:10 , RichardOnRails wrote: > > >> I pasted code to prompt for a couple of parameter-values at > >>http://www.pastie.org/1399710. > > >> Running this code under SciTE produces, for example: > >> Getting parms > >>       Account Number: 123 > >>       Report  Period: 456 > >> Showing parms > >>       @acct_num = 123 > >>       @acct_period = 456 > > >> It is excessively verbose because I couldn't figure out how to use > >> meta-language to specify the parameter target names. > > > It is excessively verbose because you wrote 53 lines when 4 would do: > > > print "Account Number: " > > @acct_num = gets.to_i > > print "Report  Period: " > > @acct_period = gets.to_i > > > There is nothing wrong with that code. It doesn't have to be 13x more complex to ask the user 2 simple questions. > > > The definition of DRY is "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system" not "ZOMG I see a 2 line pattern! must kill!" > > > Please. Do the simplest thing that could possibly work. > > > P.S. AGAIN with the tabs. I almost didn't write this email at all just because reading your code is too hard. > > Hi, > 1) I don't think you need an Array of Hash. Just a Hash. You're right. That's much better > 2) I used "eval" to do what you want > > Was it something like this what you wanted? I thought about eval, but I didn't know how to apply it to get result that you did. Your solution is EXACTLY the kind of solution I imagined but couldn't implement. Thank you very much, Richard