百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

memoist

> 编程语言
开源

ActiveSupport::Memoizable(带有少量增强功能)

923 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

ActiveSupport::Memoizable(带有少量增强功能)

Memoist Memoist 是 ActiveSupport::Memoizable 的一个扩展。 自 2011 年 6 月起, ActiveSupport::Memoizable 已被淘汰。 但我非常喜欢它, 所以我打算让它继续存在。 ## 使用方法 只需扩展 Memoist 模块即可。 ```ruby

require 'memoist' class Person extend Memoist

def social_security puts "execute!" decrypt_social_security end memoize :social_security end

person = Person.new

person.social_security

execute!

=> (returns decrypt_social_security)

person.social_security

=> (returns the memoized value)

从而, person.social_security 只会被计算一次。 每个 memoized 函数 (最初不接受任何参数) 都有一个 `(reload)` 参数, 你可以传递给它来绕过和重置 memoization:ruby def some_method Time.now end memoize :some_method 执行 some_method 将会被 memoized, 但执行 some_method(true) 则每次都会重新 memoize。 你甚至可以 memoize 接受参数的方法。ruby class Person def taxes_due(income) income * 0.40 end memoize :taxes_due end


# 相关链接

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言