Ruby: How do I stop execution and print a string in a loop? -


i writing rake task. thing want stop execution of task when if keeper.has_trevance_info? && candidate.has_trevance_info? true. want print another record has info! in log , stop task. how that? raise or throw?

  billing_infos.each |candidate|     unless keeper.nil?       raise "another record has info! manually compare billinginfo ##{keeper.id}              , ##{candidate.id}" if keeper.has_trevance_info? && candidate.has_trevance_info?      else       keeper = candidate     end    end 

you don't want use exception handling exit task. can use 'abort' or 'exit'.

so code this:

billing_infos.each |candidate|   unless keeper.nil?     if keeper.has_trevance_info? && candidate.has_trevance_info?       puts "another record has info! manually compare billinginfo ##{keeper.id}"       exit     end   else     keeper = candidate   end end 

or:

billing_infos.each |candidate|   unless keeper.nil?     abort("another record has info! manually compare billinginfo ##{keeper.id}") if keeper.has_trevance_info? && candidate.has_trevance_info?   else     keeper = candidate   end end 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -