class RuboCop::Cop::Metrics::MethodLength
The maximum allowed length is configurable.
Comment lines can optionally be ignored.
This cop checks if the length a method exceeds some maximum value.
def code_length(node)
def code_length(node) lines = node.loc.expression.source.lines.to_a[1..-2] || [] lines.reject! { |line| irrelevant_line(line) } lines.size end
def message(length, max_length)
def message(length, max_length) format('Method has too many lines. [%d/%d]', length, max_length) end
def on_method(node, _method_name, _args, _body)
def on_method(node, _method_name, _args, _body) check_code_length(node) end