"Sputnik" help  
Sputnik Help
Language Reference - Classes - Class Cast Overrides - ToArray

Class Cast Overrides - ToArray

This allows a class to override the cast to an Array.

class Test
{
    my $i;
    my $j;
    Function __Construct($i, $j)
    {
        @this->$i = $i;
        @this->$j = $j;
    }
    Function __ToArray()
    {
        say "__ToArray has been run";
        return [$i, $j];
    }
}

my $a = new Test(64, 10);
printr (Array)$a;

// PRINTS
// __ToArray has been run
// Array
// (
//     [0] => Array
//         (
//             [0] => 64
//             [1] => 10
//         )
// )

A full list of all possible cast overrides can be found here.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org