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

  • Home
  • SEARCH
  • 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 808063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:30:14+00:00 2026-05-15T00:30:14+00:00

how does this work? in irb: >> class A >> b = [1, 2,3]

  • 0

how does this work?

in irb:

>> class A
>>   b = [1, 2,3]
>> end
=> [1, 2, 3]

Is b an instance variable? class variable? how would I access b from
outside the class? Is it used for meta-programming?

  • 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-15T00:30:15+00:00Added an answer on May 15, 2026 at 12:30 am

    Is b an instance variable? class variable?

    No, it’s a local variable inside the class ... end scope.

    how would I access b from outside the class?

    You wouldn’t. It goes out of scope (and is thus inaccessible) once it reaches the end.

    Is it used for meta-programming?

    It can be. Example:

    class A
      b = [1,2,3]
      b.each do |i|
        define_method("foo#{i}") do end
      end
    end
    

    I’ve now defined the methods foo1, foo2 and foo3.

    Of course this wouldn’t behave any differently if I didn’t create the variable b and just did [1,2,3].each directly. So creating a local variable by itself does nothing, it allows you to write cleaner code (the same as using local variables in a method).

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

Sidebar

Related Questions

Can you execute assert_equal from within irb? This does not work. require 'test/unit' assert_equal(5,5)
Why does this work ? var x = from p in db.People let oCount
Why does this work: result = (from e in db.CampaignCodes where e.Code.Equals() && e.Domain.Equals(null)
How does this work? protected void btnLogin_Click(object sender, EventArgs e) { //$.blockUI(); //select from
Why does this work SELECT DISTINCT FIRSTNAME, LASTNAME FROM books, CUSTOMERS, orders, orderitems WHERE
I want to do this if (typeof(variable) == undefined) {} does this work in
Why does this work: #include iostream class Something { private: static int s_nIDGenerator; int
Take, for instance, support.google.com/mail/bin/answer.py?hl=en&answer=13287 . What is that answer.py ? How does this work?
does this work on string in c++? string s=lomi; cout<<s<<endl; what is bad in
Why does this work var v = document.getElementsByTagName(video)[0]; v.play(); And this $(#movie).play(); or this

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.