Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created April 11, 2024 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1n3l0/61a7c994cf2928fb982239e41e0907d2 to your computer and use it in GitHub Desktop.
Save j1n3l0/61a7c994cf2928fb982239e41e0907d2 to your computer and use it in GitHub Desktop.
Inherit private attributes in Object::Pad
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