1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
class Foo attr_reader :bar def bar=(value) @bar = value + 2 end end foo = Foo.new foo.bar = 4 puts foo.bar ### class Foo { has $.bar; method bar is rw { $!bar += 2; $!bar } } my $foo = Foo.new; $foo.bar = 4; say $foo.bar;