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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:35:37+00:00 2026-06-05T04:35:37+00:00

To give a little context around how I understand the problem. Using splat collect

  • 0

To give a little context around how I understand the problem.

Using splat collect on a string sends :to_a or :to_ary to the String

class String
  def method_missing method, *args, &block
    p method #=> :to_ary
    p args   #=> []
    p block  #=> nil
  end
end

*b = "b"

So I was thinking that redefining the :to_ary method would be what I’m after.

class String
  def to_ary
    ["to_a"]
  end
end

p *a = "a" #=> "a"
p a        #=> "a"

*b = "b"
p b        #=> ["to_a"]

Now this confuses me to no end.

Printing the result from the *a = “a” changes the value assigned to a?

To demonstrate further

class String
  def to_ary
    [self.upcase!]
  end
end

p *a = "a" #=> "a"
p a        #=> "a"

*b = "b"
p b        #=> ["B"]
  • 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-05T04:35:38+00:00Added an answer on June 5, 2026 at 4:35 am

    Very interesting question! Ruby takes this expression:

     p *a = "a"
    

    and translates it to something like this:

     temp = (a = "a")
     p *temp
    

    So the first thing that happens is that a gets assigned to "a", and then the result of the assignment expression which is "a" gets splatted and sent to p. Since p‘s default behaviour when sent multiple arguments is just to iterate over and print each one, you only see "a" appear.

    In short, it follows a “assign then splat” order of evaluation. So a gets assigned to "a" before the string gets splatted.

    When you don’t have a function call however, it is interpreted as something like this:

    # *a = "a" gets interpreted as:
    temp = "a"
    a = *temp
    

    This follows a “splat then assign” order of evaluation. So a gets assigned after the string gets splatted.

    You can see what’s being received by a function by going like this:

    def foo *args
      puts args.inspect
    end
    
    foo *a = "a"    # outputs ["a"]
    a               # outputs "a"
    

    Hope this clears up what’s going on!

    In short (thanks to Mark Reed):

    p *a = "a"    # interpreted as: p(*(a = "a"))
    *a = "a"      # interpreted as: a = *("a")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think the title is fairly self explanatory, but to give a little context.
Just to give a little more context to the question, I have a web
I have come across the same problem, but maybe I can give a little
To first give a little bit of context, my use-case is that my partner
So to give a little context, my goal here is to produce a binary
I'm starting to give a little more attention to making my javascript and ajax
Could someone give me a little direction on creating crossfades/dissolves between two UIImageViews in
I'm a little confused as to why this doesn't give an error. I found
I'm a .NET developer who knows very little about Python, but want to give
Greetings Guru's, This is a little hard to explain, but I'll give it a

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.