I am a Java / C ++ programmer, and Ruby is my first scripting language. Sometimes it seems to me that I do not use it as productively as I could in some areas, for example, for example:
Purpose: to analyze only certain lines from a file. The sample I'm going to make is that there is one very large line with a size greater than 15, the rest are certainly smaller. I want to ignore all lines up to (and including) large.
def do_something(str) puts str end str = 'ignore me me too! LARGE LINE ahahahahha its a line! target1 target2 target3' flag1 = nil str.each_line do |line| do_something(line) if flag1 flag1 = 1 if line.size > 15 end
I wrote this, but I think it can be written much better, i.e. There should be a better way than setting a flag. Recommendations on how to write beautiful Ruby lines are also welcome.
Note / Clarification: I need to print ALL lines after the first appearance of LARGE LINE.
ruby coding-style
Zombies
source share