Jump to content

Add a variable to a class instance at runtime: Difference between revisions

Line 1,033:
 
=={{header|Perl 6}}==
{{works in|Rakudo|2015.12}}
You can add variables/methods to a class at runtime by composing in a role. The role only affects that instance, though it is inheritable. An object created from an existing object will inherit any roles composed in with values set to those at the time the role was created. If you want to keep changed values in the new object, clone it instead.
<lang perl6>class Bar { } # an empty class
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.