[MacRuby] #423: #respond_to? returns true, actual method call raises NoMethodError
#423: #respond_to? returns true, actual method call raises NoMethodError ---------------------------------+------------------------------------------ Reporter: ecin@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ framework 'Cocoa' a = NSMetadataQuery.new a.respond_to? :setPredicate # => true a.setPredicate # => NoMethodError: undefined method `setPredicate' for #<NSMetadataQuery:0x2002a1e20> a.setPredicate "a" # => RuntimeError: NSInvalidArgumentException: -[NSCFString generateMetadataDescription]: unrecognized selector sent to instance 0x2002309c0 -- Ticket URL: <http://www.macruby.org/trac/ticket/423> MacRuby <http://macruby.org/>
#423: #respond_to? returns true, actual method call raises NoMethodError ---------------------------------+------------------------------------------ Reporter: ecin@… | Owner: martinlagardette@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ Changes (by lsansonetti@…): * owner: lsansonetti@… => martinlagardette@… -- Ticket URL: <http://www.macruby.org/trac/ticket/423#comment:1> MacRuby <http://macruby.org/>
#423: #respond_to? returns true, actual method call raises NoMethodError ---------------------------------+------------------------------------------ Reporter: ecin@… | Owner: martinlagardette@… Type: enhancement | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ Changes (by martinlagardette@…): * priority: major => minor * type: defect => enhancement Old description:
framework 'Cocoa'
a = NSMetadataQuery.new
a.respond_to? :setPredicate # => true
a.setPredicate # => NoMethodError: undefined method `setPredicate' for #<NSMetadataQuery:0x2002a1e20>
a.setPredicate "a" # => RuntimeError: NSInvalidArgumentException: -[NSCFString generateMetadataDescription]: unrecognized selector sent to instance 0x2002309c0
New description: {{{ #!ruby framework 'Cocoa' a = NSMetadataQuery.new a.respond_to? :setPredicate # => true a.setPredicate # => NoMethodError: undefined method `setPredicate' for #<NSMetadataQuery:0x2002a1e20> a.setPredicate "a" # => RuntimeError: NSInvalidArgumentException: -[NSCFString generateMetadataDescription]: unrecognized selector sent to instance 0x2002309c0 }}} -- Comment: Hi! Thanks for the report. However, the `undefined method 'setPredicate'` is raised because `setPredicate` (without argument) doesn't exist. On the other hand, the `RuntimeError` is raised because, as the error says, you are sending an invalid argument (`NSInvalidArgumentException`) to `setPredicate:`. `NSString`s are not valid parameters to `setPredicate:`.[[BR]] As you can see, `setPredicate:` is trying to send `generateMetadataDescription` to `NSString`, which is why the error says `unrecognized selector sent to instance`. It is not targeted to the `NSMetadataQuery`, but to the `NSString` you sent as a parameter. Here is a correct way of using `setPredicate:`: {{{ #!ruby framework 'Cocoa' q = NSMetadataQuery.new pre = NSPredicate.predicateWithFormat("grade = '7'", nil) p q.respond_to? :setPredicate # => true p q.setPredicate pre # => #<NSMetadataQuery:0x200230fe0> }}} However, I will try to see if we can change the `undefined method` into something like `missing parameter` or `valid candidates` etc. :-) -- Ticket URL: <http://www.macruby.org/trac/ticket/423#comment:2> MacRuby <http://macruby.org/>
#423: #respond_to? returns true, actual method call raises NoMethodError ---------------------------------+------------------------------------------ Reporter: ecin@… | Owner: martinlagardette@… Type: enhancement | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ Comment(by martinlagardette@…): I forgot to add (I whish I could edit my posts), this: {{{ #!ruby q = NSMetadataQuery.new p q.respond_to? "setPredicate:" # => true p q.respond_to? "setPredicate" # => true }}} Should, as you reported, return false for the second call, instead of true. -- Ticket URL: <http://www.macruby.org/trac/ticket/423#comment:3> MacRuby <http://macruby.org/>
#423: #respond_to? returns true, actual method call raises NoMethodError ---------------------------------+------------------------------------------ Reporter: ecin@… | Owner: martinlagardette@… Type: enhancement | Status: assigned Priority: minor | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ Changes (by martinlagardette@…): * status: new => assigned Comment: Actually, after further analysis, `respond_to?` should be fine the way it is now.[[BR]] `respond_to? :test` on ruby methods returns true wether it has arguments, or not.[[BR]] Obj-C message passing differs, and in theory, `-test` != `-test:`, but I highly doubt there are any cases where the difference will be needed.[[BR]] I will however see if there is a way / a need to improve the error that pops outon `-test` when only `-test:` is defined, but `#respond_to?` works fine for now. -- Ticket URL: <http://www.macruby.org/trac/ticket/423#comment:4> MacRuby <http://macruby.org/>
#423: #respond_to? returns true, actual method call raises NoMethodError ---------------------------------+------------------------------------------ Reporter: ecin@… | Owner: martinlagardette@… Type: enhancement | Status: closed Priority: minor | Milestone: MacRuby 0.6 Component: MacRuby | Resolution: fixed Keywords: | ---------------------------------+------------------------------------------ Changes (by martinlagardette@…): * status: assigned => closed * resolution: => fixed * milestone: => MacRuby 0.6 Comment: This is now fixed: {{{ #!ruby # /tmp/test.rb framework 'Cocoa' q = NSMetadataQuery.new pre = NSPredicate.predicateWithFormat("grade = '7'", nil) p q.respond_to? "setPredicate" begin p q.setPredicate rescue => e p e ensure p q.setPredicate pre end }}} {{{ $> ./miniruby /tmp/test.rb true #<ArgumentError: wrong number of arguments (0 for 1)> #<NSMetadataQuery:0x200021420> }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/423#comment:5> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby