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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:29:37+00:00 2026-05-30T19:29:37+00:00

look this class: class Test def initialize a, b, c @a = a, @b

  • 0

look this class:

class Test
  def initialize a, b, c
    @a = a, @b = b, @c = c
  end
  end

class AnotherTest
  def initialize a, b, c
    @a = a
    @b = b
    @c = c
  end
end

array = []

array.push Test.new "a1" ,"b1", "c1"
array.push AnotherTest.new "a2" ,"b2", "c2"

p array

I think this should be the same,but not:

<Test:0x000000022aba78 @b="b1", @c="c1", @a=["a1", "b1", "c1"]>
<AnotherTest:0x000000022ab9b0 @a="a2", @b="b2", @c="c2">]

Anybody who can give me an explain?

  • 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-30T19:29:38+00:00Added an answer on May 30, 2026 at 7:29 pm

    If you try in irb this expression:

    a = "something" #=> "something"
    

    As you can see, the assignment operation returns the result, because in ruby every expression should return something. So then this expression:

    @b = b #=> b
    

    will return the value of @b. Then in this expression

    @a = a, @b = b, @c = c
    

    where @b = b and @c = c will evaluate to b and c

    So finally we will have this expression:

    @a = a, b, c
    

    And as you know it’s another form for initialization of array

    @a = [a, b, c]
    

    This code will work equivalently to yours:

    class Test
      def initialize a, b, c
        @a = a, b, c
        @b = b
        @c = c
      end
    end
    

    Addition:
    The order of evaluating is significant.
    If you try this expression:

    @a = a, (@b = b, @c = c)
    

    Firstly, it will evaluate everything in parentheses:

    @b = b, @c = c #=> @b = [b,c] and @c = c
    

    So then we’ll get this

    @a = [a,[b,c]]
    @b = [b,c]
    @c = c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at this code: public class Test { public static void main(String...
In Java, it would look like this: class Foo { float[] array; } Foo
Please, take a look at this example: import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Test
I have controller methods that look like this: class TestController < ApplicationController def testAction
I've got a set of models that look like this: class Page(models.Model): title =
In Java, a 'static method' would look like this: class MyUtils { . .
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
I currently have service classes that look something like this public class UserService :
take a look at this example code: public class Comment { private Comment() {

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.