Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的最终用途是在 Rails 中,我在其中分配一个实现each动作的对象response.body。
each
response.body
每个方法都很长,我想分解它。但是由于显式和隐式块之间的性能差异,我想保持块隐式。
如何让分解的方法屈服于原始块?
实际上,在发布我的问题后,我意识到如何做到这一点。答案是使用带有参数的块调用子方法并产生参数:
def each submethod1 {|out| yield out} submethod2 {|out| yield out} yield "whatever" end def submethod1 yield "submethod1" end def submethod2 yield "submethod2" end