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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:45:33+00:00 2026-05-30T22:45:33+00:00

I was trying to write my first method_missing override when I kept running into

  • 0

I was trying to write my first method_missing override when I kept running into (edited) stack level too deep errors. The main culprit seemed to be trying to utilize an instance attribute. For instance if ‘self’ was a instance of the User class then checking for something like:

def method_missing(name)
  if self.name
    # do stuff
  end
end

Would seg fault. I spent a long time on this but ended up giving up. There must be something I’m not understanding about accessing it.

Edit

My apologies, Andrew is correct, I am getting Stack Level too deep errors. With this in mind, what is the appropriate (if any) way to access the instances attribute values?

  • 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-30T22:45:35+00:00Added an answer on May 30, 2026 at 10:45 pm

    You can potentially rectify this problem by ensuring that self.name actually exists:

    def method_missing(name)
      if self.respond_to?(:name) && self.name
        # do stuff
      end
    end
    

    Note this may not work if your class inherits from anything Railsy (e.g. ActiveRecord::Base), since it overrides respond_to?.

    If you are in a Railsy class, your method missing should call super, lest you lose a lot of the “magic” ActiveRecord methods (including, probably, self.name itself):

    def method_missing(name, *args, &block)
      if name_is_something_i_should_handle_here
        # do your stuff
      else
        super(name, *args, block) # call parent's method_missing
      end
    end
    

    Obviously you should replace name_is_something_i_should_handle_here with the appropriate logic.

    You may also wish to consider using dynamic method creation instead of method_missing.

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

Sidebar

Related Questions

I am trying to write my first real python function that does something real.
I'm trying to write my first iterator class / container type. Basically, I want
I am trying to write my first WCF project. I have created a project
I'm trying to write my first iPhone app, and I'm using a date picker
Currently I'm trying to write my first Python library and I've encountered the following
I am trying to write a JavaScript function that will return its first argument(function)
I'm trying to write some code to Hide columns if the first 3 characters
I'm trying to write some code to remove the first N characters in a
I am trying to write a query that connects 3 tables. The first table
I am trying to write my first class in objective-c and i want to

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.