instance_eval方法在其块中更改self,例如:
class D; end
d = D.new
d.instance_eval do
puts self # print something like #<D:0x8a6d9f4>, not 'main'!
end
Run Code Online (Sandbox Code Playgroud)
如果我们定义一个方法selfelf(或任何其他方法(除了instance_eval)接受一个块),当print self时,我们将得到'main',这与instance_eval方法不同.eg:
[1].each do |e|
puts self # print 'main'
end
Run Code Online (Sandbox Code Playgroud)
如何定义像instance_eval这样的方法(采用块)?提前致谢.
多数提交数据和多数提交数据的快照之间有什么区别,我应该关心它吗?如果这两个概念完全不同,何时以及如何选择一个?
我在阅读有关 mongodb 中事务的参考时发现了这些描述:https://docs.mongodb.com/manual/core/transactions/#transaction-options-read-concern-write-concern-read-preference,但我不明白之间的差别readConcern: majority和readConcern: snapshot。