Ruby articles

Jean Lazarou


Here are notes about the Ruby language.


The Actor pattern in GUI with Swiby/JRuby. (February 17, 2007) *

After reading an article talking about applying the Actor pattern for GUI, I decided to write the example in JRuby (the original article presented a Java version and a Python version).

The JRuby implementation is easier to use (and to understand) than the Java version (see the article).

method_missing, the price to pay. (August 6, 2007) *

Are you playing with method_missing? Did you hear it could lead to inefficient code? Here is an example and some benchmarks (see the article for a complete explanation).

As a quick summary, the benchmark runs some test first by calling a normal method (see Normal method), next by always going through the method_missing (see Always missing). Then, it adds a new method, so that next time the method does exist (see Create method). Finally, it adds a new optimized method (Optimized).

Next are the results produced on a Windows-XP system, with Ruby 1.8.5.

Creating a method has 30% of gain. The optimized version is even much better (93% of gain) but is specific to the example. Except the optimized version, the other two are less efficient than a normal call (the better one adds 21% overhead).

The same test on a Linux box, with Ruby 1.8.5, produces:

The exact gain percentage is different, still we see that creating a method improves performance but is not as good as normal calls. Of course, the optimized version remains the best.