On Thu, 17 Nov 2005, David A. Black wrote:

>> i went through the ChangeLog but didn't see anything that jumped out.  the
>> change makes sense - but will in continue to be this way?  is the move to
>> return appropriate sub-classed values meant to be pervasive?
>
> I think the appropriateness is questionable.  I guess the point would be to
> make it easier to subclass built-in classes.  But it actually sort of
> constrains what you can do.
>
> For example:
>
> irb(main):012:0> def C.new(str); raise ArgumentError, "C's can't be
> shorter than 5 characters" if str.size < 5; super(str); end
> => nil
> irb(main):013:0> C.new('abcde')[0,2]
> => "ab"
> irb(main):014:0> C.new('abcde')[0,2].class
>
> So it doesn't really provide a whole mechanism for building on
> built-ins.  There's probably more to the rationale for it, though.

i don't understand how it's supposed to work unless copy constructor semantics
are worked out.  for example


   harp:~ > cat a.rb
   require "md5"

   class C < ::String
     attr "md5"
     def initialize *a, &b
       super
       @md5 = MD5::md5 self
     end
   end

   c = C::new 'forty-two'
   p c.class
   p c.md5

   cu = c.upcase
   p cu.class
   p cu.md5

   harp:~ > ruby a.rb
   C
   a16ca146e5e432fa7e30319121ea7473
   C
   nil


so, while it seems simple to return an instance of the String sub-class as a
return value, how can it possible without having some sort of rule/hook for
initialization in these cases?  as the above shows the return value will be
half baked.

regards.

-a
-- 
===============================================================================
| ara [dot] t [dot] howard [at] gmail [dot] com
| all happiness comes from the desire for others to be happy.  all misery
| comes from the desire for oneself to be happy.
| -- bodhicaryavatara
===============================================================================