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)


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

def body_on_first_line?(node, body)
  same_line?(node, body)
end

#first_part_of(body) ⇒ Object



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

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
# 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