Reflection/List properties: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 622:
}, 'Circle' );
</pre>
=={{header|Perl 6}}==
 
You can get a list of an object's attributes (instance variables) using <tt>.^attributes</tt>, which is part of the [https://docs.perl6.org/type/Metamodel$COLON$COLONClassHOW Meta Object Protocol]..<br>
Each is represented as an <tt>Attribute</tt> object that contains a bunch of info:
 
<lang perl6>class Foo {
has $!a = now;
has Str $.b;
has Int $.c is rw;
 
my $object = Foo.new: b => "Hello", c => 42;
 
for $object.^attributes {
say join ", ", .name, .readonly, .container.^name, .get_value($object);
}</lang>
 
{{out}}
<pre>
$!a, True, Any, Instant:1470517602.295992
$!b, True, Str, Hello
$!c, False, Int, 42
</pre>
 
Public attributes (in this case, <tt>$.b</tt> and <tt>$.c</tt>) are really just attributes for which the compiler also auto-generates a method of the same name. See [[Reflection/List_methods#Perl_6]].
 
=={{header|Phix}}==
Line 846 ⟶ 821:
#[('__class__', <class '__main__.Child'>), ..., ('args', (0, 'I', 'two')), ('args_bleh', "(0, 'I', 'two') bleh"), ('doNothing', <bound method Child.doNothing of Child(chld, 0, 'I', 'two')>), ('doStuff', <bound method Child.doStuff of Child(chld, 0, 'I', 'two')>), ('name', 'chld'), ('name_bleh', 'chld bleh'), ('own', "chld's own"), ('own_bleh', "chld's own bleh"), ('reBleh', <_sre.SRE_Pattern object at 0x10067bd20>), ('reBleh_bleh', '<_sre.SRE_Pattern object at 0x10067bd20> bleh')]
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
 
You can get a list of an object's attributes (instance variables) using <tt>.^attributes</tt>, which is part of the [https://docs.perl6.org/type/Metamodel$COLON$COLONClassHOW Meta Object Protocol]..<br>
Each is represented as an <tt>Attribute</tt> object that contains a bunch of info:
 
<lang perl6>class Foo {
has $!a = now;
has Str $.b;
has Int $.c is rw;
 
my $object = Foo.new: b => "Hello", c => 42;
 
for $object.^attributes {
say join ", ", .name, .readonly, .container.^name, .get_value($object);
}</lang>
 
{{out}}
<pre>
$!a, True, Any, Instant:1470517602.295992
$!b, True, Str, Hello
$!c, False, Int, 42
</pre>
 
Public attributes (in this case, <tt>$.b</tt> and <tt>$.c</tt>) are really just attributes for which the compiler also auto-generates a method of the same name. See [[Reflection/List_methods#Perl_6]].
 
=={{header|REXX}}==
10,333

edits