Hi,

In message "Re: Subrange of String subclass => invalid object"
    on 02/01/28, Dave Thomas <Dave / PragmaticProgrammer.com> writes:

|> Don't feel sorry.  I agree it's sloppy.  Maybe I didn't think enough
|> deep when I accepted this RCR.  Let's discuss for "better way".
|
|I think one of the underlying issues here is nothing to do with
|sub-objects. Instead it's the fact that the interpreter bypasses the
|constructors for many built-in types althogether. Thus is is basically
|impossible to enforce contracts on (say) Strings.


The original surprise in [ruby-talk:32417] can not be solved
automaticaly in any way, because it's just not defined.  I guess it's
OK to surprise at the original situation, as long as there's a way to
fix the problem.  But we provide no "hook" to fix this surprise in the
current String implementation (in your words: "bypasses the
constructor").  This is a problem.

There're several way to provide the "hook":

  (a) invoke "initialize"
      ..but, argument pattern has to be preserved for subclasses, in
      this case.

  (b) invoke "dup"
      ..but, you have to needless copy.

  (c) invoke something to initialize object from another object
      ..far better than mere dup (maybe dup will also call this
      method), but we should choose a good name for it.

  (d) _String? as you proposed
      ..but, I'm still not sure how it serves.  Maybe too much for the
      problem.

  (e) something else
      ..but someone got to tell me that something.

Personally I like (c) above.  But I seldom be a good name chooser.

							matz.