Skip to content

Latest commit

 

History

History
61 lines (49 loc) · 894 Bytes

Lint-NestedMethodDefinition.md

File metadata and controls

61 lines (49 loc) · 894 Bytes

Pattern: Nested method definition

Issue: -

Description

This rule checks for nested method definitions.

Examples

# bad

# `bar` definition actually produces methods in the same scope
# as the outer `foo` method. Furthermore, the `bar` method
# will be redefined every time `foo` is invoked.
def foo
  def bar
  end
end
# good

def foo
  bar = -> { puts 'hello' }
  bar.call
end
# good

def foo
  self.class_eval do
    def bar
    end
  end
end

def foo
  self.module_exec do
    def bar
    end
  end
end
# good

def foo
  class << self
    def bar
    end
  end
end

Further Reading