Thursday, 15 September 2011

idioms - Setting variables with blocks in ruby -


I'm able to use a lot of loops in loops, like PHP and when the rest of the language is very clear I Running with code like this:

  conditions_string = '' zips.each_with_index do | Zip, i Terms_string & lt; & Lt; 'Or' if i & gt; 0 terms_string & lt; & Lt; "NAPA =?" End # Now I can do something with some string  

I think I should be able to do something like this

  conditions_string = zips.each_with_index Do Zip, eye. & Lt; & Lt; 'Or' if i & gt; 0 & lt; & Lt; "NAPA =?"        

= "Text">

Are not accessing zip , so the following should work:

conditions_string = ([npa =? '] * Zips.length) .Join (' OR ')

If you need access to zip , then you can use it:

  conditions_string = Zips.collect {| ZIP | | 'Npa =?'}. Join ('OR')  

No comments:

Post a Comment