Skip to content

rb/proc

blocks and lambda expressions

clojure
(proc)

Matching:

  1. brace blocks, e.g. { |x| x }
  2. do/end blocks, e.g. do |x| x end
  3. lambda expressions, e.g. ->(x) { x }

Behavior

  • Matches blocks and lambdas; does not match Proc.new calls.

Examples

Audit all blocks and lambdas before refactoring iteration patterns.

clojure
(proc)

Selects in lines { 1, 0, 5 } but not in { }:

ruby
items.each { |x| x + 1 }
items.map do |x|
  x * 2
end
transform = ->(x) { x + 1 }

Find lambdas used as callbacks.

clojure
(:and (proc) (:text /->/))

Selects in lines { 1 } but not in { 2 }:

ruby
handler = ->(x) { x + 1 }
items.each { |x| x + 1 }

Copyright © 2022-present Semantic Works, Inc.