Module: Fastererer::ReceiverFactory

Defined in:
lib/fastererer/method_call.rb

Constant Summary collapse

PRIMITIVE_NODE_TYPES =
[Prism::ArrayNode, Prism::RangeNode, Prism::IntegerNode,
Prism::FloatNode, Prism::SymbolNode, Prism::StringNode,
Prism::HashNode].freeze

Class Method Summary collapse

Class Method Details

.build(node) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/fastererer/method_call.rb', line 106

def self.build(node)
  return unless node

  node = unwrap_parentheses(node)
  case node
  # A ConstantPathNode's #name is the unqualified tail only (Foo::Bar => :Bar), which is all
  # the symbol-to-proc check needs; revisit if a check ever needs the fully-qualified path.
  when Prism::LocalVariableReadNode, Prism::ConstantReadNode,
       Prism::ConstantPathNode then VariableReference.new(node)
  when Prism::CallNode then MethodCall.build(node)
  when *PRIMITIVE_NODE_TYPES then Primitive.new(node)
  end
end

.unwrap_parentheses(node) ⇒ Object

Peels a single parenthesis level, so ‘((x))` stays wrapped — matches how callers normalize



121
122
123
124
125
126
127
128
129
# File 'lib/fastererer/method_call.rb', line 121

def self.unwrap_parentheses(node)
  if node.is_a?(Prism::ParenthesesNode) &&
     node.body.is_a?(Prism::StatementsNode) &&
     node.body.body.size == 1
    node.body.body.first
  else
    node
  end
end