We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 41a96a7 commit 02705f2Copy full SHA for 02705f2
lib/dry/core/memoizable.rb
@@ -85,6 +85,8 @@ def define_memoizable(method:)
85
value = super()
86
87
if kernel[:frozen].bind(self).call
88
+ # It's not possible to modify singleton classes
89
+ # of frozen objects
90
mod.remove_method(method.name)
91
mod.module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
92
def #{method.name} # def slow_calc
@@ -98,6 +100,10 @@ def #{method.name} # def slow_calc
98
100
end # end
99
101
RUBY
102
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 :)
107
attr_name = :"__memozed_#{key}__"
108
ivar_name = :"@#{attr_name}"
109
kernel[:ivar_set].bind(self).(ivar_name, value)
0 commit comments