Ruby Object中是否有一种方法可以将自身传递给块或proc? [英] Is there a method in Ruby Object to pass itself to a block or proc?
问题描述
我认为在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?
推荐答案
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
这篇关于Ruby Object中是否有一种方法可以将自身传递给块或proc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!