Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Proc#eql?

prc.eql?(other) → true or false

Alias of #==

Two procs are the same if, and only if, they 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 #== #curry #hash #call also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0