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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:56:53+00:00 2026-05-27T15:56:53+00:00

Edited I originally asked about doing this in one line; I meant to say

  • 0

Edited

I originally asked about doing this in one line; I meant to say one statement. I’ve edited the question accordingly.


Suppose I have a method that returns a two-item array, like a color and a day of the week.

def make_tuple
  [['blue', 'red', 'orange'].sample, ['Mon','Wed', 'Fri'].sample]
end
make_tuple # =>  ['orange', 'Wed']

I can capture the output in two separate variables like this:

color, day = make_tuple

I can gather those outputs into two separate collections like this:

colors ||= []
days   ||= []
colors << color
days   << day

Is there a way to combine these two steps – getting separate values from the tuple and appending them to separate existing collections – into one statement? For instance:

# Doesn't work
colors <<, days << = make_tuple
  • 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-27T15:56:54+00:00Added an answer on May 27, 2026 at 3:56 pm

    Some examples, both functional and imperative style:

    def make_tuple
      [['blue', 'red', 'orange'].sample, ['Mon','Wed', 'Fri'].sample]
    end
    
    # Functional creation of pairs with N elements
    colors, days = 3.times.map { make_tuple }.transpose
    #=> [["blue", "blue", "blue"], ["Wed", "Wed", "Mon"]]
    
    # Functional append (creates new arrays)
    colors2, days2 = [colors, days].zip(make_tuple).map { |ar, x| ar + [x] }
    #=> [["blue", "blue", "blue", "red"], ["Wed", "Wed", "Mon", "Fri"]]
    
    # Imperative append
    [colors, days].zip(make_tuple) { |pair, p| pair << p } 
    #=> [["blue", "blue", "blue", "red"], ["Wed", "Wed", "Mon", "Fri"]]
    
    # Imperative append building an abstraction Array#zip_append
    class Array
      def zip_append(items)
        zip(items) { |array, item| array << item }
      end
    end
    
    [colors, days].zip_append(make_tuple)
    #=> [["blue", "blue", "blue", "red"], ["Wed", "Wed", "Mon", "Fri"]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I originally posted a much simpler (and less helpful) question, and have edited this
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Disclaimer : I already asked this question , but without the deployment requirement. I
Ok, i kind of asked the wrong question so I've edited the original question.
[EDITED] This issue was originally described as my having trouble with Perl's Socket, but
I have edited the original question since the same error is occurring the difference
Edited Original question was about trouble with reconnecting (close() and shutdown() confusion). The below
Edited to add more details: (originally asked nearly two months ago...still haven't found a
Edited because I'm a moron. Should have said class originally. I have the code
Question This question was originally to find out if anyone knows of a way

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.