Skip to content

Commit ee43bb8

Browse files
author
Jan-Olof Hendig
committed
Added some documentation for the 'freeze' method. #perl6++
1 parent 03dd1b5 commit ee43bb8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/Type/Pair.pod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,23 @@ Usage:
127127
128128
Returns a list of one C<Pair>, namely this one.
129129
130+
=head2 method freeze
131+
132+
Defined as:
133+
134+
method freeze(Pair:D:)
135+
136+
Usage:
137+
138+
PAIR.freeze
139+
140+
Makes the I<value> of the C<Pair> read-only, by removing it from its L<Scalar container|/language/containers#Scalar_containers>, and returns it.
141+
142+
my $str = "apple";
143+
my $p = Pair.new('key', $str);
144+
$p.value = "orange"; # this works as expected
145+
$p.say; # key => orange
146+
$p.freeze.say; # orange
147+
$p.value = "a new apple"; # Fails with 'Cannot modify an immutable Str'
148+
130149
=end pod

0 commit comments

Comments
 (0)