Parent

Methods

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::Lambda

This cop checks for uses of the pre 1.9 lambda syntax for one-line anonymous functions and uses of the 1.9 lambda syntax for multi-line anonymous functions.

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/style/lambda.rb, line 14
def on_block(node)
  # We're looking for
  # (block
  #   (send nil :lambda)
  #   ...)
  block_method, = *node

  return unless block_method == TARGET
  selector = block_method.loc.selector.source
  lambda_length = lambda_length(node)

  if selector != '->' && lambda_length == 0
    add_offense(block_method, :expression, SINGLE_MSG)
  elsif selector == '->' && lambda_length > 0
    add_offense(block_method, :expression, MULTI_MSG)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.