class Rubocop::Cop::Style::SingleLineMethods
This cop checks for single-line method definitions. It can optionally accept single-line methods with no body.
Constants
- MSG
Public Instance Methods
allow_empty?()
click to toggle source
# File lib/rubocop/cop/style/single_line_methods.rb, line 11 def allow_empty? SingleLineMethods.config['AllowIfMethodIsEmpty'] end
on_def(node)
click to toggle source
Calls superclass method
# File lib/rubocop/cop/style/single_line_methods.rb, line 15 def on_def(node) check(node) super end
on_defs(node)
click to toggle source
Calls superclass method
# File lib/rubocop/cop/style/single_line_methods.rb, line 21 def on_defs(node) check(node) super end
Private Instance Methods
check(node)
click to toggle source
# File lib/rubocop/cop/style/single_line_methods.rb, line 29 def check(node) start_line = node.loc.keyword.line end_line = node.loc.end.line if node.type == :def empty_body = node.children[2].nil? else empty_body = node.children[3].nil? end if start_line == end_line && !(allow_empty? && empty_body) add_offence(:convention, node.loc.expression, MSG) end end