[MacRuby] #1487: isEmpty() from ObjC
#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/>
#1487: isEmpty() from ObjC ----------------------------------+----------------------------------------- Reporter: iloveitaly@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): String#count has been implemented as Ruby's method in MacRuby. http ://ruby-doc.org/core-1.9.2/String.html#method-i-count "a.count" in your code invokes Ruby's method. -- Ticket URL: <http://www.macruby.org/trac/ticket/1487#comment:1> MacRuby <http://macruby.org/>
#1487: isEmpty() from ObjC ----------------------------------+----------------------------------------- Reporter: iloveitaly@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): And same method has been implemented in NSString for compatibility with Ruby. {{{ irb(main):001:0> str = NSString.stringWithString("foo") => "foo" irb(main):002:0> str.count ArgumentError: wrong number of arguments irb(main):003:0> str.count "o" => 2 }}} You might need to avoid "count" method. -- Ticket URL: <http://www.macruby.org/trac/ticket/1487#comment:2> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby