qtruby, QUiLoader and respond_to?
Posted
by Tim Sylvester
on Stack Overflow
See other posts from Stack Overflow
or by Tim Sylvester
Published on 2010-04-02T19:34:12Z
Indexed on
2010/04/03
19:53 UTC
Read the original article
Hit count: 300
I'm writing a simple Qt4 application in Ruby (using qtruby) to teach myself both. Mostly it has gone well, but in trying to use Ruby's "duck typing" I've run into a snag; respond_to?
doesn't seem to reflect reality.
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'Qt4'
=> true
irb(main):003:0> require 'qtuitools'
=> true
irb(main):004:0> Qt::Application.new(ARGV)
=> #<Qt::Application:0xc3c9a08 objectName="ruby">
irb(main):005:0> file = Qt::File.new("dlg.ui") { open(Qt::File::ReadOnly) }
=> #<Qt::File:0xc2e1748 objectName="">
irb(main):006:0> obj = Qt::UiLoader.new().load(file, nil)
=> #<Qt::Dialog:0xc2bf650 objectName="dlg", x=0, y=0, width=283, height=244>
irb(main):007:0> obj.respond_to?('children')
=> false
irb(main):008:0> obj.respond_to?(:children)
=> false
irb(main):009:0> obj.children
=> [#<Qt::FormInternal::TranslationWatcher:0xc2a1980 objectName="">, ...
As you can see, when I check to ensure that the object I get back from loading the UI file has a children
accessor I get false
. If call that accessor, however, I get an array rather than a NoMethodError
.
So, is this a bug or have I incorrectly understood respond_to?
?
This looks like the problem described here, but I thought I would get an expert opinion before filing a bug against the project.
© Stack Overflow or respective owner