ruby – “Proc#==”如何评估?
发布时间:2020-12-16 20:22:03 所属栏目:百科 来源:网络整理
导读:Proc#==如何评估? RDoc说: prc == other_proc → true or false Returns true if prc is the same object as other_proc,or if they are both procs with the same body. 但是不清楚什么是“同一个机构”.一个条件似乎是,理性必须是一样的: -{} == -{} #
Proc#==如何评估?
RDoc说:
但是不清楚什么是“同一个机构”.一个条件似乎是,理性必须是一样的: ->{} == ->{} # => true ->{} == ->x{} # => false ->x{} == ->x{} # => true ->x{} == ->y{} # => true ->x{} == ->y,z{} # => false 但是还有更多的.正如RDoc所说,身体重要: ->{nil} == ->{nil} # => true ->{nil} == ->{false} # => false ->{false} == ->{false} # => true 但同时,看起来proc没有被完全评估: ->{} == ->{nil} # => false ->{false} == ->{1 == 2} # => false 身体在多大程度上评估? 解决方法
这有
changed in Ruby 2.0,所以你不应该尝试比较Procs.他们不会是==,除非它们是完全相同的对象.
讨论可以是found here. 如果您真的需要比较两个代码块,并使用MRI,您可以使用RubyVM :: InstructionSequence.disassemble(block),甚至更好地在Ruby 2.0 RubyVM :: InstructionSequence.of(block)中使用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |