Module: RuboCop::Cop::TrailingBody

Included in:
LineBreakCorrector, Style::TrailingBodyOnClass, Style::TrailingBodyOnMethodDefinition, Style::TrailingBodyOnModule
Defined in:
lib/rubocop/cop/mixin/trailing_body.rb

Overview

Common methods shared by TrailingBody cops

Instance Method Summary collapse

Instance Method Details

#body_on_first_line?(node, body) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rubocop/cop/mixin/trailing_body.rb', line 13

def body_on_first_line?(node, body)
  node.source_range.first_line == body.source_range.first_line
end

#first_part_of(body) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/rubocop/cop/mixin/trailing_body.rb', line 17

def first_part_of(body)
  if body.begin_type?
    body.children.first.source_range
  else
    body.source_range
  end
end

#trailing_body?(node) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
# File 'lib/rubocop/cop/mixin/trailing_body.rb', line 7

def trailing_body?(node)
  body = node.to_a.reverse[0]
  body && node.multiline? &&
    body_on_first_line?(node, body)
end