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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:27:55+00:00 2026-06-18T12:27:55+00:00

As the subject states, I experienced a stack overflow when playing with singleton methods

  • 0

As the subject states, I experienced a stack overflow when playing with singleton methods in IRB. Below is the code I’ve tried:

c= C.new
class << c
  def class
    "my class is #{self.class}."
  end
end

When I called c.class, I got a:

SystemStackError: stack level too deep
Maybe IRB bug!

I found a reference on how to adjust stack sizes but don’t understand what stack sizes are in the first place.

Question:
Why did I get that error in IRB? Also, how can I continue experimenting with Ruby singleton/class methods?

  • 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-18T12:27:56+00:00Added an answer on June 18, 2026 at 12:27 pm

    First things first, there is some thing called recursion where a function can call itself. This is what you have unintentionally done in your code.

    The second thing, the stack is something which maintains the function call trace. So that when end of recursion or stack level depth has been reached, it can correctly resume the program.

    Its something like this:
    Say you have function A and function B.

    function A {
      /* some code */
      B()
      /* some more code */
    }
    
    function B {
      return / * something * /
    }
    

    Your machine basically halts executing A, saves the state of variables in A onto a stack, calls and executes B. When finally B exits, it pops from the stack and resumes executing A.

    In that specific example, since you wish to define your own class method. The following code should do:

    def class
      "my class is #{super}"
    end
    

    Hope this helps.

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

Sidebar

Related Questions

Well - exactly as the question subject states - any ideas on how you
I am a experienced developer that is new to iOS developement (on iPhone in
Just like the subject states. I want to be able to run iisreset, batch
Model: class ExpertLevel(models.Model): level = models.CharField(max_length=100) subject = models.ManyToManyField(Subject, blank=True, null=True) class Expert(models.Model): appuser
I have the following XML: <tickets> <ticket> <subject>ABC</subject> <entries-field> <entry-field> <field-id>12345</field-id> <value>New</value> </entry-field> <entries-field>
So as the subject states I need to be able to answer a phone
As the subject states, is the mvc model that is used in ASP.Net MVC
I have SubjectGroup, which hasMany Subject. class SubjectGroup extends AppModel { public $hasMany =
I have to do a class project for data mining subject. My topic will
Let's assume we are designing a Stack class test-first (TDD): public class Stack<T> {

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.