This book of yours should be relatively old, and the Ruby version you are using is before 2.0. Starting with Ruby 2.0, the behavior of Proc#== has changed:
Starting with Ruby 2.0, Two procs are == only when they are the same object.只有当两个 proc 是同一对象时,== 才返回 true.
Looking at ruby’s official documentation, lambda is actually Proc. Proc does not overload its own == method, but calls BasicObject ’s == method
Equality — At the Object level, == returns true only if obj and other are the same object (The method of comparing objects at the Object level is to determine whether they are the same object). Typically, this method is overridden in descendant classes to provide class-specific meaning.
Proc
Look at the base class of Proc and you can see that it inherits from Object, and then Object inherits from BasicObject
Version problem.
This book of yours should be relatively old, and the
Ruby
version you are using is before 2.0. Starting with Ruby 2.0, the behavior of Proc#== has changed:Starting with Ruby 2.0,
Two procs are == only when they are the same object.
只有当两个 proc 是同一对象时,==
才返回true
.Reference:
https://bugs.ruby-lang.org/issues/4559
https://github.com/ruby/ruby/blob/f031aec4233d7a6d4622c048abed3e86eb5dd6c2/NEWS#L127-130
Looking at ruby’s official documentation, lambda is actually Proc.
Proc does not overload its own == method, but calls BasicObject
’s == method
Proc
Look at the base class of Proc and you can see that it inherits from Object, and then Object inherits from BasicObject