[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bindings
Subject:    [Kde-bindings] Module#constants redefined by korundum takes the
From:       Stefano Crocco <stefano.crocco () alice ! it>
Date:       2010-12-14 8:41:43
Message-ID: 4C88E33B07A66662 () smtp204 ! alice ! it (added by postmaster () alice ! it)
[Download RAW message or body]

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)
    end
  else
    def constants _arg = true
      qt_methods(_constants, 0x10, true)
    end
  end

end

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

Stefano
_______________________________________________
Kde-bindings mailing list
Kde-bindings@kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic