[MacRuby] #1091: #inspect behaves differently if class uses #init or custom #init method

MacRuby ruby-noreply at macosforge.org
Fri Dec 31 10:59:44 PST 2010


#1091: #inspect behaves differently if class uses #init or custom #init method
---------------------------+------------------------------------------------
 Reporter:  haxie1@…       |       Owner:  lsansonetti@…        
     Type:  defect         |      Status:  new                  
 Priority:  blocker        |   Milestone:                       
Component:  MacRuby        |    Keywords:                       
---------------------------+------------------------------------------------

Comment(by haxie1@…):

 Replying to [ticket:1091 haxie1@…]:
 > Ruby docs for #inspect say that the default implementation just calls
 #to_s.  (http://www.ruby-doc.org/core/classes/Object.html#M000360)
 >
 > If my class is initialized with a custom #init method that doesn't seem
 to be the case.
 >
 > {{{
 > class Foo
 >     def to_s
 >         "I am Foo"
 >     end
 > end
 >
 > Foo.new.inspect
 > "I am Foo"
 >
 > class Bar
 >     def initMe
 >         return self
 >     end
 >
 >     def to_s
 >          "I am Bar"
 >     end
 > end
 > Bar.alloc.initMe.inspect
 > "#<Bar:0x2000c0960>"
 >
 > Bar.alloc.initMe.to_s
 > "I am Bar"
 > }}}
 >
 > Should #inspect do something different based on how I initialize my
 class?

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/1091#comment:1>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list