下面两个thrice
方法的Ruby语言实现在行为上有什么不同?
module WithYield
def self.thrice
3.times { yield } # yield to the implicit block argument
end
end
module WithProcCall
def self.thrice(&block) # & converts implicit block to an explicit, named Proc
3.times { block.call } # invoke Proc#call
end
end
WithYield::thrice { puts "Hello world" }
WithProcCall::thrice { puts "Hello world" }
我所说的“行为差异”包括错误处理、性能、工具支持等。
https://stackoverflow.com/questions/1410160
复制相似问题