Skip to content

Commit 02705f2

Browse files
committed
Add comments
1 parent 41a96a7 commit 02705f2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/dry/core/memoizable.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def define_memoizable(method:)
8585
value = super()
8686

8787
if kernel[:frozen].bind(self).call
88+
# It's not possible to modify singleton classes
89+
# of frozen objects
8890
mod.remove_method(method.name)
8991
mod.module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
9092
def #{method.name} # def slow_calc
@@ -98,6 +100,10 @@ def #{method.name} # def slow_calc
98100
end # end
99101
RUBY
100102
else
103+
# We make an attr_reader for computed value.
104+
# Readers are "special-cased" in ruby so such
105+
# access will be the fastest way, faster than you'd
106+
# expect :)
101107
attr_name = :"__memozed_#{key}__"
102108
ivar_name = :"@#{attr_name}"
103109
kernel[:ivar_set].bind(self).(ivar_name, value)

0 commit comments

Comments
 (0)