RubyFlow The Ruby and Rails community linklog


The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

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

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in