class RuboCop::Cop::Style::ModuleFunction
This cops checks for use of `extend self` or `module_function` in a module.
Supported styles are: module_function, extend_self.
@example
# Good if EnforcedStyle is module_function module Test module_function ... end # Good if EnforcedStyle is extend_self module Test extend self ... end
These offenses are not auto-corrected since there are different implications to each approach.
Constants
- EXTEND_SELF_MSG
- MODULE_FUNCTION_MSG
Public Instance Methods
on_module(node)
click to toggle source
# File lib/rubocop/cop/style/module_function.rb, line 37 def on_module(node) _name, body = *node return unless body && body.begin_type? each_wrong_style(body.children) do |child_node| add_offense(child_node) end end
Private Instance Methods
each_wrong_style(nodes) { |node| ... }
click to toggle source
# File lib/rubocop/cop/style/module_function.rb, line 48 def each_wrong_style(nodes) case style when :module_function nodes.each do |node| yield node if extend_self_node?(node) end when :extend_self nodes.each do |node| yield node if module_function_node?(node) end end end
message(_node)
click to toggle source
# File lib/rubocop/cop/style/module_function.rb, line 61 def message(_node) style == :module_function ? MODULE_FUNCTION_MSG : EXTEND_SELF_MSG end