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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:30:42+00:00 2026-06-10T07:30:42+00:00

Given a = [[:a, :b, :c]] 1) I understand this a.each{|(x, y), z| p

  • 0

Given

a = [[:a, :b, :c]]

1) I understand this

a.each{|(x, y), z| p z} # => :b

that there are two variables (x, y) and z, so the third element :c is thrown away, and z matches :b. And I understand this

a.each{|(x, y), z| p y} # => nil

that (x, y) matches :a, and since it is not an array, there are no elements to it, and so y matches nil.

But how does

a.each{|(x, y), z| p x} # => :a

work? I expect nil to be returned.

2) Why are the return values like this?

a.each{|(x, y)| p x} #=> :a
a.each{|(x, y)| p y} #=> :b

I expect them to both return nil.

  • 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-06-10T07:30:44+00:00Added an answer on June 10, 2026 at 7:30 am

    It’s because of the syntax of parallel assignment.

    a = [[:a, :b, :c]]
    

    So a.each has only one element to iterate, which is [:a, :b, :c].

    In the first case:

    (x, y), z = [:a, :b, :c]
    #=> x == :a, y == nil, z == :b
    

    Here (x, y) is an array to match the first element :a, and x gets it, then z simply matches the second element :b.

    And in the second case:

    (x, y) = [:a, :b, :c]
    #=> x == :a, y == :b
    

    Here (x, y) as an entire array matches the array [:a, :b, :c], so x and y get :a and :b respectively.

    This is just like requiring the “args + optional args (keyword args) + rest args” combination match provided arguments. It is just smart enough to take arguments by sequence.

    Another smart example:

    (a,b) = 1,2
    => [1, 2] # array match
    #=> a == 1, b == 2
    
    (a,b)=[1,2]
    => [1, 2] # array match
    #=> a == 1, b == 2
    

    In either case above, it will simply make the best guess on what it should take.

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

Sidebar

Related Questions

I understand that CoCreateInstance finds the COM server for the given class id, creates
I want to understand how a C++ program that was given to me works,
I just can't seem to understand how this would work. Question: Given a sequential
The following code when compiled give this error I cannot understand why this is
Given the Ruby code line = first_name=mickey;last_name=mouse;country=usa record = Hash[*line.split(/=|;/)] I understand everything in
I'm trying to understand how parallelism might work using PLINQ, given delayed execution. Here
Gonna give an example since it's hard to understand what i'm talking about: SELECT
Given that the web application doesn't have su privileges, I'd like to execute a
First of all, I understand that it's unusual that I want to up-convert like
So I basically have two subviews within my main view. I created each subview

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.