RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  

Multidispatch feature in Ruby

If you worked with other languages you probably familiar with feature called multi dispatching or multimethods. It is the feature of some object-oriented programming languages in which a function or method can be dynamically dispatched based on the run time (dynamic) type of more than one of its arguments.

For example in C# it will be:

public void Multi(D d, A a) { System.Console.WriteLine("DA"); }
public void Multi(D d, B b) { System.Console.WriteLine("DB"); }
public void Multi(D d, C c) { System.Console.WriteLine("DC"); }
public void Multi(E e, A a) { System.Console.WriteLine("EA"); }
public void Multi(E e, B b) { System.Console.WriteLine("EB"); }
public void Multi(E e, C c) { System.Console.WriteLine("EC"); }

If you like the idea and want to add it to your ruby code check out multidispatch_dsl


Post a Comment

Comment abilities for non registered users are currently deactivated, pending time to add a proper CAPTCHA to solve the escalating spam problem. Sorry!