Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 554511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:43:03+00:00 2026-05-13T11:43:03+00:00

I am a Java/C++ programmer and Ruby is my first scripting language. I sometimes

  • 0

I am a Java/C++ programmer and Ruby is my first scripting language. I sometimes find that I am not using it as productively as I could in some areas, like this one for example:

Objective: to parse only certain lines from a file. The pattern I am going with is that there is one very large line with a size greater than 15, the rest are definitely smaller. I want to ignore all the lines before (and including) the large one.

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 could be written a lot better, ie, there must be a better way than setting a flag. Recommendations for how to write beautiful lines of Ruby also welcome.

Note/Clarification: I need to print ALL lines AFTER the first appearance of the LARGE LINE.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:43:03+00:00Added an answer on May 13, 2026 at 11:43 am
    str.lines.drop_while {|l| l.length < 15 }.drop(1).each {|l| do_something(l) }
    

    I like this, because if you read it from left to right, it reads almost exactly like your original description:

    Split the string in lines and drop lines shorter than 15 characters. Then drop another line (i.e. the first one with more than 14 characters). Then do something with each remaining line.

    You don’t even need to necessarily understand Ruby, or programming at all to be able to verify whether this is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner java programmer. I'm working on an application that decrypts some data.
As a very novice Java programmer, I probably should not mess with that kind
I am not a Java programmer. I program R and C++. I have some
I am a programmer with strong background in Java, Ruby, Python and other high
I am a Java programmer who learns Haskell. I've written a small program that
I am a java programmer, I found that Java is very good at doing
I am a Java programmer and was working on a project using Hibernate and
So, I'm normally a ruby programmer, so my grasp of Java conventions is shaky
I'm not a java programmer, I'm a VB programmer. I am doing this as
I'm a java programmer, but now entering the realm of python for some stuff

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.