Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Proc#==

(untyped other) -> bool
self == other → true or false

Returns whether self and other were created from the same code block:

Example
def return_block(&block)
  block
end

def pass_block_twice(&block)
  [return_block(&block), return_block(&block)]
end

block1, block2 = pass_block_twice { puts 'test' }
# Blocks might be instantiated into Proc's lazily, so they may, or may not,
# be the same object.
# But they are produced from the same code block, so they are equal
block1 == block2
#=> true

# Another Proc will never be equal, even if the code is the "same"
block1 == proc { puts 'test' }
#=> false

Ruby version changes

  1. 3.0
See also #<< #=== .new #>> also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0