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 1103893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:24:22+00:00 2026-05-17T01:24:22+00:00

How could I make this shorter and extendable: def overview puts All As: for

  • 0

How could I make this shorter and extendable:

  def overview
    puts "All As:"
    for f in @a
      puts f
    end
    puts "\n"  

    puts "All Bs:"
    for f in @b
      puts f
    end
  end
  • 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-17T01:24:23+00:00Added an answer on May 17, 2026 at 1:24 am
    for f in @a
      puts f
    end
    

    can we written

    puts @a.join("\n")
    

    In the general case, when you want to do something with several arrays you can put the arrays into an array and then use each e.g.

    [@a, @b].each do |list|
      list.each { |value| puts value }
    end
    

    and once you get onto doing something more complicated than just printing out the values it makes sense to use the extract method refactoring on the operation you’re performing e.g.

    [@a, @b].each do |list|
      do_something_with list
    end
    

    Finally, if you need to keep descriptive labels (“All As” etc.) you can use a hash:

    {'As' => @a, 'Bs' => @b}.each_pair do |label, values|
        puts "All #{label}"
        puts values.join("\n")
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could you help me to make this query faster. My query is workable, but
I know I could just make all the Mix_Musics public, and not worry about
Is there anyway I can make this database code any shorter ? It works
I'm trying to find jQuery functions that might make this jQuery code shorter. I
I have the feeling that using joins could make this cleaner public override string[]
Basically my mate has been saying that I could make my code shorter by
I was wondering if I could make a large number of system calls at
Is there a python lib that could make a 2-dimensional list of (R,G,B) data
I am curious how I could make a PHP script where you pass your
It seems that both of them could make the element move from its current

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.