On 1/26/06, Stevan Little <[EMAIL PROTECTED]> wrote:
> > If there is need to treat something as a Hash, then provide it with a
> > postcircumfix<{}> and leave it at that. It's highly unlikely that you
> > will want to add Hash-like behavior to something that already has a
> > postcircumfix<{}> because it probably has that behavior already.
>
> Well this is in relation to how to deal with an object which is a
> blessed p6hash, in which case you may or may not want to have a
> ^Hash-like interface for it (you might even want to overload the
> ^Hash-like interface too).

[snip]

> Now, in order for C<$self as Hash> to make sense, $self would have to
> be coercable into a Hash in some way. If $self is a blessed p6array
> this might not make that much sense, so we would die because the
> coercion failed. However, if $self is a blessed p6hash, then it would
> make plenty of sense (IMO at least). It would allow us to get at the
> underlying representation without having to sacrifice flexibility in
> the class from which $self came. Basically you could do things like
> this:
>
> class Golum;
>
> method new (Golum $class, Hash %params) {
>     $class.bless(%params);
> }
>
> method postcircumfix:<{}> (Golum $self, Any $key, Any $value) {
>      die "Nasssty Hobbitses" if $value.does(Hobbit);
>      $self as Hash {
>         $self{$key} = $value;
>     }
> }

How about just inheriting from Hash?

class Gollum extends Hash;

method postcircumfix:<{}> (Golum $self, Any $key, Any $value) {
     die "Nasssty Hobbitses" if $value.does(Hobbit);
    $self.NEXT.{}( $key, $value );
}

Rob

Reply via email to