rubocop-hq/rubocop-ast

View on GitHub
lib/rubocop/ast/utilities/simple_forwardable.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module RuboCop
  # Similar to `Forwardable#def_delegators`, but simpler & faster
  module SimpleForwardable
    def def_delegators(accessor, *methods)
      methods.each do |method|
        class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
          def #{method}(...)           # def example(...)
            #{accessor}.#{method}(...) #   foo.example(...)
          end                          # end
        RUBY
      end
    end
  end
end