Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint/NestedMethodDefinition shouldn't flag singleton methods #2898

Closed
CyborgMaster opened this issue Feb 29, 2016 · 3 comments
Closed

Lint/NestedMethodDefinition shouldn't flag singleton methods #2898

CyborgMaster opened this issue Feb 29, 2016 · 3 comments

Comments

@CyborgMaster
Copy link

I have the following method that dynamically creates a subclass

  def setup
    subclass = Class.new SimpleCommunicationSetting do
      def self.template
        {
          name: 'test',
        }
      end
    end
  end

which gets flagged with the following offense:

test/models/comm_engine/communication_settings/simple_communication_setting_test.rb:6:7: W: Lint/NestedMethodDefinition: Method definitions must not be nested. Use lambda instead.  (https://github.com/bbatsov/ruby-style-guide#no-nested-methods)
      def self.template
      ^^^^^^^^^^^^^^^^^

It appears that there should be a test for this: does not register offense for nested definition inside Class.new, but maybe the passed in superclass is confusing it?

RuboCop version

$ rubocop -V
0.37.2 (using Parser 2.3.0.5, running on ruby 2.2.2 x86_64-darwin14)
@segiddins
Copy link
Contributor

I've got a fix for this I'll PR in a second

@CyborgMaster
Copy link
Author

Thanks! You guys rock!

@bbatsov bbatsov closed this as completed in 116a4a7 Mar 1, 2016
bbatsov added a commit that referenced this issue Mar 1, 2016
…ew-superclass

[Fix #2898] Allow method definitions inside Class.new(SuperClass)
@CyborgMaster
Copy link
Author

Sweet. May we please have a bugfix release to RubyGems?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants