Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/memoist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def flush_cache(*method_names)
remove_instance_variable(ivar) if instance_variable_defined?(ivar)
end
end

def set_cache(method_name, value)
memoized_ivar = Memoist.memoized_ivar_for(method_name)
instance_variable_set(memoized_ivar, value)
end
end

def memoize(*method_names)
Expand Down
7 changes: 7 additions & 0 deletions test/memoist_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,11 @@ def test_private_method_memoization
assert_equal 1, person.is_developer_calls
end

def test_memoization_with_custom_value
person = Person.new
person.set_cache(:is_developer?, "No")
assert_equal "No", person.send(:is_developer?)
assert_equal 0, person.is_developer_calls
end

end