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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:24:43+00:00 2026-06-16T16:24:43+00:00

Adding the following code to an object is supposed to allow me to retrieve

  • 0

Adding the following code to an object is supposed to allow me to retrieve the singleton class of any object.

class Object
    def singleton_class
        class << self; self; end
    end
end

I had a Powerball class, which I instantiated this way

puts Powerball.new.singleton_class
puts Powerball.new.singleton_class
puts Powerball.singleton_class
puts Powerball.singleton_class

It gave me this output

#<Class:#<Powerball:0x007fd333040548>>
#<Class:#<Powerball:0x007fd333040408>>
#<Class:Powerball>
#<Class:Powerball>

So, the two instances of the powerball class have unique ids, while calling singleton_class directly on the class doesn’t yield an object id.

Questions

  1. Are the ids unique because each instance has a singleton class?

  2. I understand that self within a class just returns the Class i.e. Class:Powerball, but since a class is an object, shouldn’t it also have an id? Is there a way to access that id?

  • 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-16T16:24:44+00:00Added an answer on June 16, 2026 at 4:24 pm

    You’ll have to understand that singleton class belongs to an instance. First two singletons in your code belonged to two different Powerball instances. (Yes, each instance has its very own singleton class – it’s called singleton because only that one instance ever belongs to it.) The 3rd and 4th singleton was the same – singleton class of the Powerball class itself, which, of course, is the same object in both cases.

    Why don’t you try investigating by yourself:

    class Kokot; end
    puts Kokot.object_id
    puts Kokot.singleton_class.object_id
    

    And also, in Ruby 1.9.x, #singleton_class is a built-in method.

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

Sidebar

Related Questions

The following code run correctly: import pickle class MyClass(): def __init__(self, arg): self.arg =
Consider the following code: public abstract class Test1 { public object Data { get;
I am adding a handler to textbox using the following code: private void frmLogin_Load(object
In the following code: public class StringCache { private readonly object lockobj = new
I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {
In the following code segment when built I keep breaking when adding the OnClickListener
I am using the following code for adding a listener in prefernceactivity. But its
I have the following code for adding to/extracting from Zip. I'm trying to refactor
I am using the following code for adding full permission for the image files
the following plotLine object on the xAxis is adding lines to both panes how

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.