Class: Henitai::Mutant::ParameterSource

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/mutant/parameter_source.rb

Overview

Builds the parameter-list fragment of a define_method block from a subject’s method-definition AST node.

Given the def/defs/block node for a method, #build returns the comma-separated parameter source (e.g. “a, b = 1, *rest, key:, &blk”) suitable for splicing into a define_method(:name) do |…| … template.

Constant Summary collapse

SERIALIZER_METHODS =
{
  arg: :argument_parameter_fragment,
  optarg: :optional_parameter_fragment,
  restarg: :rest_parameter_fragment,
  kwarg: :keyword_parameter_fragment,
  kwoptarg: :optional_keyword_parameter_fragment,
  kwrestarg: :keyword_rest_parameter_fragment,
  blockarg: :block_parameter_fragment,
  forward_arg: :forward_parameter_fragment
}.freeze

Instance Method Summary collapse

Instance Method Details

#build(subject_node) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/henitai/mutant/parameter_source.rb', line 26

def build(subject_node)
  args_node = method_arguments(subject_node)
  return "" unless args_node
  return forward_parameter_fragment(nil) if args_node.type == :forward_args

  args_node.children.filter_map do |argument|
    parameter_fragment(argument)
  end.join(", ")
end