[MacRuby] #1487: isEmpty() from ObjC

MacRuby ruby-noreply at macosforge.org
Sun Mar 25 11:19:22 PDT 2012


#1487: isEmpty() from ObjC
----------------------------------+-----------------------------------------
 Reporter:  iloveitaly@…          |       Owner:  lsansonetti@…        
     Type:  defect                |      Status:  new                  
 Priority:  blocker               |   Milestone:                       
Component:  MacRuby               |    Keywords:                       
----------------------------------+-----------------------------------------
 I have this function in objc:
 {{{
 static inline BOOL isEmpty(id thing) {
     return thing == nil
         || ([thing respondsToSelector:@selector(length)]
         && [(NSData *)thing length] == 0)
         || ([thing respondsToSelector:@selector(count)]
         && [(NSArray *)thing count] == 0);
 }
 }}}

 From an objc class, if I run:

 {{{
 NSString *a = @"testing";
 isEmpty(a);
 }}}

 I get the following error from macruby:
 {{{
 rb_main.rb:38:in `<main>': can't convert Class into String (TypeError)
 }}}

 This is caused by the specific line in isEmpty():

 {{{
 [(NSArray *)thing count] == 0)
 }}}

 I think that has something to do with:
 {{{
 $ macirb
 irb(main):001:0> a = "testing"
 => "testing"
 irb(main):002:0> a.respondsToSelector :count
 => 1
 irb(main):004:0> a.count
 ArgumentError: wrong number of arguments
 }}}

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/1487>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list