• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Ruby Object是否有一种方法可以自身传递把块或proc?

用户头像
it1352
帮助1

问题说明

我认为在Ruby中添加以下内容是很自然的:

I think it would be natural to have in Ruby something like:

class Object
  def yield_self
    yield(self)
  end
end

是否存在这样的方法? (我还没有找到.)还有其他人认为拥有它会很好吗?

Does there exist a method like this by any chance? (I haven't found.) Does anybody else think it would be nice to have it?

正确答案

#1

yield_self添加到ruby core. https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/58528

yield_self has been added to ruby core a month ago as of June 2017. https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/58528

在修订号58528之后,它位于ruby 2.5.0中,尽管我不确定如何获得该代码.也许如果有人知道如何编辑此答案

It's in ruby 2.5.0 after revision number 58528, although I'm not exactly sure how to get that code yet. Perhaps if someone knows how they can edit this answer

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfgcif
系列文章
更多 icon
同类精品
更多 icon
继续加载