[Kde-bindings] Module#constants redefined by korundum takes the wrong number of arguments in ruby 1.9

Stefano Crocco stefano.crocco at alice.it
Tue Dec 14 08:41:43 UTC 2010

Hello to everyone,
I just read on the ruby mailing list a message describing an incompatibility 
between qt-ruby and activesupport on ruby 1.9. You can find the text of the 
message at http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/375416

The cause of this issue is that korundum redefines Module#constants at line 
3130 of qtruby4.rb so that it takes no arguments. This is correct in ruby 1.8, 
where Module#constants as defined in ruby core doesn't take any arguments. In 
ruby 1.9, instead, Module#constants takes one optional argument. From the ri 
documentation of Module#constants in ruby 1.9:

= Module#constants

(from ruby core)
  mod.constants(inherit=true)    -> array


Returns an array of the names of the constants accessible in mod. This
includes the names of constants in any included modules (example at start of
section), unless the all parameter is set to false.

  IO.constants.include?(:SYNC)        #=> true
  IO.constants(false).include?(:SYNC) #=> false

This means that, with ruby 1.9, the Module#constants redefined in korundum4 is 
not compatible with the one defined in core ruby. This will cause 
incompatibilities not just with activesupport, but with just everything which 
calls constants with one argument.

The solution to this problem is very simple. It would be enough to either give 
a default (unused) argument to the redefined Module#constants regardless of 
the ruby version or to define Module#constants in a different way according to 
the ruby version:

class Module

  if RUBY_VERSION < '1.9'
    def constants
      qt_methods(_constants, 0x10, true)
    def constants _arg = true
      qt_methods(_constants, 0x10, true)


The advantage of this second approach would be that the redefined method would 
have the same number of arguments as the original one in both versions of 
ruby, thus avoiding problems with libraries which make use of the arity of the 
method to do some kind of introspection or meta-programming.

Thanks in advance for the attention


More information about the Kde-bindings mailing list