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

Nested method definition inside class << obj is reported as offense #4218

Closed
buehmann opened this issue Mar 30, 2017 · 0 comments
Closed

Nested method definition inside class << obj is reported as offense #4218

buehmann opened this issue Mar 30, 2017 · 0 comments

Comments

@buehmann
Copy link
Contributor

One false positive of Lint/NestedMethodDefinition was not covered by the fix for #4185:

class Foo
  def x(obj)
    class << obj
      def y
      end
    end
  end
end
bug.rb:4:7: W: Method definitions must not be nested. Use lambda instead.
      def y ...
      ^^^^^

Expected behavior

I expect RuboCop not do register an offense for nested defs like these.

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.48.0 (using Parser 2.4.0.0, running on ruby 2.3.1 x86_64-darwin15)
Drenmi added a commit to Drenmi/rubocop that referenced this issue Mar 31, 2017
…shovel scope

This cop would register an offense on nested method definitions when the
inner definition was inside a "class shovel" scope, e.g.:

```
def foo
  class << self
    def bar; end
  end
end
```

This change fixes that.
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

1 participant