Skip to content

Fix Naming/MethodName define method issue with equality #14350

@bkuhlmann

Description

@bkuhlmann

Expected behavior

I would expect the following to not cause an error:

def define_equality
  define_method(:==) { |other| other.is_a?(self.class) && hash == other.hash }
end

Actual behavior

Here's the output I see:

demo:16:17: C: Naming/MethodName: Use snake_case for method names. (https://rubystyle.guide#snake-case-symbols-methods-vars)
  define_method(:==) { |other| other.is_a?(self.class) && hash == other.hash }
                ^^^^

The problem is that RuboCop doesn't like the symbolized version equality (:==). ...but I'm guessing this to be an issue with any method using special characters as an argument to define_method.

Steps to reproduce the problem

Use the following code snippet with the latest release of RuboCop to recreate:

def define_equality
  define_method(:==) { |other| other.is_a?(self.class) && hash == other.hash }
end

RuboCop version

1.78.0 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.1, analyzing as Ruby 3.4, running on ruby 3.4.4) [arm64-darwin24.5.0]
  - rubocop-capybara 2.22.1
  - rubocop-disable_syntax 0.2.0
  - rubocop-packaging 0.6.0
  - rubocop-performance 1.25.0
  - rubocop-thread_safety 0.7.3
  - rubocop-rake 0.7.1
  - rubocop-rspec 3.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions