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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:28:45+00:00 2026-05-26T05:28:45+00:00

Are there any situations where a dispatch table, implemented as a hash of lambdas,

  • 0

Are there any situations where a dispatch table, implemented as a hash of lambdas, might be as good, if not better, than over-riding Ruby’s method_missing? I’m asking because I used this technique today as I’m a comparative newbie with Ruby, but have previously had a Perl background, and the dispatch table example in Wikipedia is even implemented in Perl 😉 See:

http://en.wikipedia.org/wiki/Dispatch_table

In any event, also, what are the drawbacks to using a dispatch table instead of method_missing. Maybe my Ruby code below gives a clue? It would seem that my dispatch table could grow quite large, and there’s no way to access the lambdas it contains for use in another context. So maybe I’m answering my question to some extent, but I’m really interested in when a dispatch table might be a better solution than method_missing or other meta programming techniques, thanks

def dispatch_self_and_modified_ancestors(key, value, work_effort)
    dispatch_table = {
        :scheduled_completion_date => lambda {|work_effort, updated_value|
            modified_ancestors = []

            while work_effort.parent
                work_effort = work_effort.parent
                if updated_value > work_effort.scheduled_completion_date
                    work_effort.scheduled_completion_date = updated_value
                    work_effort.save
                    modified_ancestors.push work_effort
                else
                    break
                end
            end

            return modified_ancestors
        }
    }

    if dispatch_table.has_key?(key)
        return dispatch_table[key].call(work_effort, value)
    else
        return []
    end
end
  • 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-26T05:28:46+00:00Added an answer on May 26, 2026 at 5:28 am

    If you are frequently calling something caught by method_missing, the act of searching for a nonexistent method may end up being a performance issue in your code. So a dispatch table might be one way of working around that.

    Here’s a good article describing the performance issues of method_missing and attempts at optimizing them: http://www.alef1.org/ruby/method_missing/

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

Sidebar

Related Questions

Are there any situations where using will not dispose of the object it is
(See question below for more context): Are there any situations in which <machineKey validationKey=AutoGenerate,IsolateApps
Is there any good resource for getting started with iOS development if you're an
Are there any situations where it would make more sense to use a single
Are there any good ways to objectively measure a query's performance in Oracle 10g?
Why isn't graphics acceleration turned on by default in Honeycomb? Are there any situations
Is there any real reason not to make a member function virtual in C++?
Are there any situations when you would use assertion instead of exceptions-handling inside domain
What I mean is are there any situations where this: <xs:element name=MyType1> <xs:complexType> <xs:sequence>
Is there any situation where I would have to set the focus on a

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.