Module: RuboCop::SimpleForwardable
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Extended In:
AST::CollectionNode ,
AST::NodePattern ,
AST::NodePattern::Compiler ,
AST::NodePattern::Compiler::Debug ,
AST::NodePattern::Node ,
AST::NodePattern::Node::AnyOrder ,
AST::NodePattern::Node::Capture ,
AST::NodePattern::Node::Predicate ,
AST::NodePattern::Node::Repetition ,
AST::NodePattern::Node::Rest ,
AST::NodePattern::Node::Sequence ,
AST::NodePattern::Node::Subsequence ,
AST::NodePattern::Node::Union ,
AST::NodePattern::Parser ,
AST::NodePattern::Parser::WithMeta
| |
Defined in: | lib/rubocop/ast/utilities/simple_forwardable.rb |
Overview
Similar to Forwardable#def_delegators
, but simpler & faster
Instance Method Summary
Instance Method Details
#def_delegators(accessor, *methods)
[ GitHub ]# File 'lib/rubocop/ast/utilities/simple_forwardable.rb', line 6
def def_delegators(accessor, *methods) methods.each do |method| if method.end_with?('=') && method.to_s != '[]=' # Defining a delegator for `foo=` can't use `foo=(...)` because it is a # syntax error. Fall back to doing a slower `public_send` instead. # TODO: Use foo(method, ...) when Ruby 3.1 is required. class_eval(<<~RUBY, __FILE__, __LINE__ + 1) def #{method}(*args, **kwargs, &blk) # def example=(*args, **kwargs, &blk) #{accessor}.public_send(:#{method}, *args, **kwargs, &blk) # foo.public_send(:example=, *args, **kwargs, &blk) end # end RUBY else class_eval(<<~RUBY, __FILE__, __LINE__ + 1) def #{method}(...) # def example(...) #{accessor}.#{method}(...) # foo.example(...) end # end RUBY end end end