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

  • SEARCH
  • Home
  • 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 7058633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:08:09+00:00 2026-05-28T04:08:09+00:00

Can this line of code be made more compact? db_tables_scanned = {} IO.readlines(resume_log_file).each {

  • 0

Can this line of code be made more compact?

db_tables_scanned = {}
IO.readlines(resume_log_file).each { |db_table| db_tables_scanned[db_table.split(".")[0].strip] << db_table.split(".")[1].strip if db_table.include? '.' } if resume and File.exists?(resume_log_file)
  • 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-28T04:08:10+00:00Added an answer on May 28, 2026 at 4:08 am

    You want a one-liner? Here’s a one-liner:

    db_tables_scanned = resume and File.exists?(resume_log_file) ? Hash[IO.readlines(resume_log_file).map { |db_table| db_table.split(".").map(&:strip) if db_table.include? '.' }.compact] : {}
    

    Of course this code is hideous. There is no need to get obsessed about getting less lines of code. Code has to:

    1. Be human-readable
    2. Use the most fitting and idiomatic abstractions of the language.

    In this case, let’s break it in lines, and use a Hash[pairs_of_keys] to build the hash:

    db_tables_scanned = if resume and File.exists?(resume_log_file)
      Hash[IO.readlines(resume_log_file).map do |db_table|
        if db_table.include?('.')
          db_table.split(".").first(2).map(&:strip)
        end  
      end.compact]
    else
      {}
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody please explain to me the meaning of this line of code? val
Can anyone convert this curl command that works in command line to php code
I would like to split a line into words. I know this can be
can you tell me how this line works.... my OperatorFactory.get(add) is not doing anything.
How can I use sed to replace this line char * path_list_[1] = {
I have this line in my program : InputStream Resource_InputStream=this.getClass().getClassLoader().getResourceAsStream(Resource_Name); But how can I
I have this html line: <time itemprop=datePublished datetime=1923-12>December 1923</time> (USA) How can i retrieve
Can I convert this into 1 command line on bash in sqlplus? cause i
How can I run this on linux command line when my username has an
I can't run this function. It gives the error: ERROR at line 9: PL/SQL:

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.