[MacRuby] #1384: Additions to class String are unusable from string created with NSString
#1384: Additions to class String are unusable from string created with NSString --------------------------------+------------------------------------------- Reporter: sohocoke@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: --------------------------------+------------------------------------------- {{{ irb(main):001:0> class String irb(main):002:1> def handy_method irb(main):003:2> puts "I'm a handy method." irb(main):004:1> end irb(main):005:0> end => nil irb(main):006:0> => nil irb(main):007:0> str1 = "a" => "a" irb(main):008:0> str1.class => String irb(main):009:0> str1.handy_method I'm a handy method. => nil irb(main):010:0> => nil irb(main):011:0> str2 = NSString.stringWithString "a" => "a" irb(main):012:0> str2.class => String irb(main):013:0> str2.class.eql? str1.class => true irb(main):014:0> str2.handy_method NoMethodError: undefined method `handy_method' for "a":String irb(main):015:0> `macruby -v` => "MacRuby 0.11 (ruby 1.9.2) [universal-darwin10.0, x86_64]\n" irb(main):016:0> }}} I expected str2.handy_method to be invoked successfully. -- Ticket URL: <http://www.macruby.org/trac/ticket/1384> MacRuby <http://macruby.org/>
#1384: Additions to class String are unusable from string created with NSString --------------------------------+------------------------------------------- Reporter: sohocoke@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: --------------------------------+------------------------------------------- Comment(by watson1978@…): I think that object which was created by NSString.stringWithString should display "NSString" class. (Similar, #1141) {{{
str2.class => String # expect => NSString }}}
{{{ $ macirb --simple
class NSString def handy_method puts "I'm a handy method." end end => nil str2 = NSString.stringWithString "a" => "a" str2.class => String str2.handy_method I'm a handy method. => nil
}}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/1384#comment:1> MacRuby <http://macruby.org/>
#1384: Additions to class String are unusable from string created with NSString --------------------------------+------------------------------------------- Reporter: sohocoke@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: --------------------------------+------------------------------------------- Comment(by watson1978@…): If you add the method to NSString, you could invoke as following. {{{
"a".handy_method I'm a handy method. }}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/1384#comment:2> MacRuby <http://macruby.org/>
#1384: Additions to class String are unusable from string created with NSString --------------------------------+------------------------------------------- Reporter: sohocoke@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: --------------------------------+------------------------------------------- Comment(by watson1978@…): String class is built on NSString. If you want to add the method to both classes, you should add the method to NSString. -- Ticket URL: <http://www.macruby.org/trac/ticket/1384#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby