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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:39:34+00:00 2026-05-24T00:39:34+00:00

I learning ruby singletons and have misunderstanding with such code: class MyClass def self.class_singleton_mymethod

  • 0

I learning ruby singletons and have misunderstanding with such code:

class MyClass
  def self.class_singleton_mymethod
  end
end

class_singleton = class << MyClass
  self
end

puts class_singleton.methods.grep(/mymethod/)  # => []


obj = MyClass.new

def obj.object_singleton_mymethod
end

object_singleton = class << obj
  self
end

puts object_singleton.methods.grep(/mymethod/) # => class_singleton_mymethod

Why class_singleton not contains class’s Class method and object_singleton instead of Object’s singleton method contains class’s Class method?

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

    I think you have the notion of methods and instance_methods mixed up. If you were to replace all instances of methods with instance_methods, you will see the results you expect.

    instance_methods is used to enumerate which methods a class’s instances have. methods is used to enumerate what methods the object has. (Class objects are objects too, and have their own methods like new that are not instance methods.

    For example, String#slice is an instance method; you can call slice on string instances. On the other hand, String.new is a method on String itself; you don’t call new on string instances, but you can call String.new (i.e., on the String class object itself) to create a new string.)

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

Sidebar

Related Questions

I'm just learning ruby and trying to understand the scope of code executed in
Is is that I'm a newbie learning Ruby, or does it really have more
Busy learning Ruby... the documentation have an example: hello world.count(lo, o) that return 2
I'm learning Ruby in my spare time, and I have a question about language
I'm just learning ruby on rails and I have a table of user roles
I still learning Ruby on Rails, but have been wondering what happens if I
I have started learning Ruby, and I have read a couple of tutorials and
I'm learning Ruby and have just gotten into some stuff about arrays and ranges.
I'm just learning Ruby on Rails (no prior Ruby experience) I have these models
I have started learning ruby and i have been looking at ruby on rails.Is

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.