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

  • Home
  • SEARCH
  • 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 168337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:26:07+00:00 2026-05-11T12:26:07+00:00

method_missing *obj.method_missing( symbol h , args i ) → other_obj Invoked by Ruby when

  • 0

method_missing

*obj.method_missing( symbol h , args i ) → other_obj

Invoked by Ruby when obj is sent a message it cannot handle. symbol is the symbol for the method called, and args are any arguments that were passed to it. The example below creates a class Roman, which responds to methods with names consisting of roman numerals, returning the corresponding integer values. A more typical use of method_missing is to implement proxies, delegators, and forwarders.

class Roman   def roman_to_int(str)     # ...   end   def method_missing(method_id)     str = method_id.id2name     roman_to_int(str)   end end r = Roman.new r.iv ! 4 r.xxiii ! 23 r.mm ! 2000 

I just heard about method-missing and went to find out more in Programming Ruby but the above explanation quoted from the book is over my head. Does anyone have an easier explanation? More specifically, is method-missing only used by the interpreter or is there ever a need to call it directly in a program (assuming I’m just writing web apps, as opposed to writing code for NASA)?

  • 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. 2026-05-11T12:26:07+00:00Added an answer on May 11, 2026 at 12:26 pm

    Ruby doesn’t have any type enforcement, and likewise doesn’t do any checking as to what methods an object has when the script is first parsed, because this can be dynamically changed as the application runs.

    What method_missing does, is let you intercept and handle calls to methods that don’t exist for a given object. This provides the under-the-hood power behind pretty much every DSL (domain-specific language) written in Ruby.

    In the case of the example, every one of ‘r.iv’, ‘r.mm’, and so on is actually a method call to the Roman object. Of course, it doesn’t have an ‘iv’ or an ‘mm’ method, so instead control is passed to method_missing, which gets the name of the method that was called, as well as whatever arguments were passed.

    method_missing then converts the method name from a symbol to a string, and parses it as a Roman number, returning the output as an integer.

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

Sidebar

Ask A Question

Stats

  • Questions 194k
  • Answers 194k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Except that you seem to be proposing to use multiple… May 12, 2026 at 6:50 pm
  • Editorial Team
    Editorial Team added an answer Since your structs are PODs you might as well do… May 12, 2026 at 6:50 pm
  • Editorial Team
    Editorial Team added an answer For the unique ID, it's pretty easy. You should take… May 12, 2026 at 6:50 pm

Related Questions

I am declaring an array of NSString* in a header file of a class.
I have an init method that takes an (id) argument: -(id) initWithObject:(id) obj; I'm
I have the following code: class IncidentTag: def __init__(self,tag): self.tag = tag def equals(self,obj):
Inspired by the MVC storefront the latest project I'm working on is using extension

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.