Module: CSVPlusPlus::Entities::ASTBuilder

Extended by:
T::Sig
Included in:
Builtins
Defined in:
lib/csv_plus_plus/entities/ast_builder.rb

Overview

Some helpful functions that can be mixed into a class to help building ASTs

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs, &block) ⇒ Entity, #super

Let the current class have functions which can build a given entity by calling it’s type. For example number(1), variable(:foo)

rubocop:disable Naming/BlockForwarding

Parameters:

  • method_name (Symbol)

    The method_name to respond to

  • args (Array)

    The arguments to create the entity with

  • kwargs (Hash)

    The arguments to create the entity with

Returns:



27
28
29
30
31
# File 'lib/csv_plus_plus/entities/ast_builder.rb', line 27

def method_missing(method_name, *args, **kwargs, &block)
  ::CSVPlusPlus::Entities.const_get(snake_case_to_class_name(method_name)).new(*args, **kwargs, &block)
rescue ::NameError
  super
end

Instance Method Details

#respond_to_missing?(method_name, *_args) ⇒ ::T::Boolean, #super

Let the current class have functions which can build a given entity by calling it’s type. For example number(1), variable(:foo)

Parameters:

  • method_name (Symbol)

    The method_name to respond to

  • _args (::T.Untyped)

    The arguments to create the entity with

Returns:

  • (::T::Boolean, #super)


42
43
44
45
46
47
# File 'lib/csv_plus_plus/entities/ast_builder.rb', line 42

def respond_to_missing?(method_name, *_args)
  ::CSVPlusPlus::Entities.const_get(snake_case_to_class_name(method_name))
  true
rescue ::NameError
  super
end