Method: RuboCop::Cop::Style::ModuleFunction#on_module

Defined in:
lib/rubocop/cop/style/module_function.rb

#on_module(node) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/rubocop/cop/style/module_function.rb', line 112

def on_module(node)
  return unless node.body&.begin_type?

  each_wrong_style(node.body.children) do |child_node|
    add_offense(child_node) do |corrector|
      next if style == :forbidden

      if extend_self_node?(child_node)
        corrector.replace(child_node, 'module_function')
      else
        corrector.replace(child_node, 'extend self')
      end
    end
  end
end