class RuboCop::Cop::Style::StructInheritance

This cop checks for inheritance from Struct.new.

@example

# bad
class Person < Struct.new(:first_name, :last_name)
  def age
    42
  end
end

# good
Person = Struct.new(:first_name, :last_name) do
  def age
    42
  end
end

Constants

MSG

Public Instance Methods

on_class(node) click to toggle source
# File lib/rubocop/cop/style/struct_inheritance.rb, line 26
def on_class(node)
  return unless struct_constructor?(node.parent_class)

  add_offense(node, location: node.parent_class.source_range)
end