Skip to content

Files

Latest commit

 

History

History
32 lines (23 loc) · 657 Bytes

Performance-BlockGivenWithExplicitBlock.md

File metadata and controls

32 lines (23 loc) · 657 Bytes

Pattern: Unnecessary block_given?

Issue: -

Description

Identifies unnecessary use of a block_given? where explicit check of block argument would suffice.

Examples

# bad
def method(&block)
  do_something if block_given?
end

# good
def method(&block)
  do_something if block
end

# good - block is reassigned
def method(&block)
  block ||= -> { do_something }
  warn "Using default ..." unless block_given?
  # ...
end

Further Reading