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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:47:01+00:00 2026-05-14T06:47:01+00:00

If I have the following piece of Ruby code: class Blah def self.bleh @blih

  • 0

If I have the following piece of Ruby code:

class Blah
  def self.bleh
    @blih = "Hello"
    @@bloh = "World"
  end
end

What exactly are @blih and @@bloh? @blih is an instance variable in the class Blah, and @@bloh is a class variable in the class Blah, correct? Does it mean that @@bloh is a variable in Blah’s class, Class?

  • 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-14T06:47:01+00:00Added an answer on May 14, 2026 at 6:47 am

    People seem to be ignoring that the method is a class method.

    @blih will be instance variable of the instance of class Class for the constant Bleh. Hence:

    irb(main):001:0> class Bleh
    irb(main):002:1>   def self.bleh
    irb(main):003:2>     @blih = "Hello"
    irb(main):004:2>     @@blah = "World"
    irb(main):005:2>   end
    irb(main):006:1> end
    => nil
    irb(main):007:0> Bleh.instance_variables
    => []
    irb(main):008:0> Bleh.bleh
    => "World"
    irb(main):009:0> Bleh.instance_variables
    => ["@blih"]
    irb(main):010:0> Bleh.instance_variable_get :@blih
    => "Hello"
    

    @@blah will be available as a class variable of Bleh:

    irb(main):017:0> Bleh.class_variables
    => ["@@blah"]
    irb(main):018:0> Bleh.send :class_variable_get, :@@blah
    => "World"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code in Visual C++ 2005 : : class
I have the following piece of code pattern: void M1(string s, string v) {
I have the following piece of code which replaces template markers such as %POST_TITLE%
I have trouble with the following piece of code. When I go through with
I have started learning Ruby recently and I was trying out the following piece
I have following piece of code: public void ProcessRequest (HttpContext context) { context.Response.ContentType =
I have following piece of code NSMutableArray *mutArray = [[NSMutableArray alloc] init]; [mutArray addObject:
I have following piece of code for reversing the linked list. I am getting
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following situation: I have loged user, standard authentication with DB table $authAdapter

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.