Created
April 11, 2024 09:59
-
-
Save j1n3l0/61a7c994cf2928fb982239e41e0907d2 to your computer and use it in GitHub Desktop.
Inherit private attributes in Object::Pad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test2::V0; | |
use Object::Pad 0.808; | |
class Power { | |
field $_power :inheritable = 0; | |
method of ($number) { $number ** $_power }; | |
}; | |
class Square { | |
inherit Power '$_power'; | |
ADJUST { $_power = 2 }; | |
}; | |
class Cube { | |
inherit Power '$_power'; | |
ADJUST { $_power = 3 }; | |
}; | |
subtest 'A "Square" object' => sub { | |
is Square->new, object { | |
call [ of => 1 ] => 1; | |
call [ of => 3 ] => 9; | |
}, 'should return the square of $number'; | |
}; | |
subtest 'A "Cube" object' => sub { | |
is Cube->new, object { | |
call [ of => 1 ] => 1; | |
call [ of => 3 ] => 27; | |
}, 'should return the cube of $number'; | |
}; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment