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

Class Cast Overrides - ToBool

This allows a class to override the cast to a Boolean.

class Test
{
    my $i;
    my $j;
    Function __Construct($i, $j)
    {
        @this->$i = $i;
        @this->$j = $j;
    }
    Function __ToBool()
    {
        say "ToBool has been run";
        return $i > 0 && $j > 0;
    }
}

my $a = new Test(10, 20);
say (Bool)$a;

// PRINTS
// ToBool has been run
// true

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


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