Class: Fastererer::MethodCall

Inherits:
Object
  • Object
show all
Defined in:
lib/fastererer/method_call.rb

Direct Known Subclasses

LambdaCall

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ MethodCall

Returns a new instance of MethodCall.



13
14
15
# File 'lib/fastererer/method_call.rb', line 13

def initialize(node)
  @element = node
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



7
8
9
# File 'lib/fastererer/method_call.rb', line 7

def element
  @element
end

Class Method Details

.build(node) ⇒ Object



9
10
11
# File 'lib/fastererer/method_call.rb', line 9

def self.build(node)
  node.is_a?(Prism::LambdaNode) ? LambdaCall.new(node) : new(node)
end

Instance Method Details

#argumentsObject



29
30
31
# File 'lib/fastererer/method_call.rb', line 29

def arguments
  @arguments ||= argument_nodes.map { |argument| Argument.new(argument) }
end

#block?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/fastererer/method_call.rb', line 41

def block?
  !block_node.nil?
end

#block_argument_namesObject



37
38
39
# File 'lib/fastererer/method_call.rb', line 37

def block_argument_names
  @block_argument_names ||= positional_block_parameter_names
end

#block_bodyObject



33
34
35
# File 'lib/fastererer/method_call.rb', line 33

def block_body
  @block_body ||= block_statements
end

#hash?Boolean

Provably a Hash: bare ‘Hash.new`/`Hash` (any args — every `Hash` yields a Hash), not qualified `Foo::Hash`. The is_a?(ConstantReadNode) check is load-bearing: ConstantPathNode#name is :Hash too, so the type (not the name) excludes qualified constants. unwrap_parentheses lets `(Hash).new` match, as the receiver factory normalizes its input.

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'lib/fastererer/method_call.rb', line 53

def hash?
  return false unless %i[new []].include?(method_name)

  constant = ReceiverFactory.unwrap_parentheses(element.receiver)
  constant.is_a?(Prism::ConstantReadNode) && constant.name == :Hash
end

#lambda_literal?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/fastererer/method_call.rb', line 45

def lambda_literal?
  false
end

#method_nameObject



21
22
23
# File 'lib/fastererer/method_call.rb', line 21

def method_name
  element.name
end

#nameObject



25
26
27
# File 'lib/fastererer/method_call.rb', line 25

def name
  method_name
end

#receiverObject



17
18
19
# File 'lib/fastererer/method_call.rb', line 17

def receiver
  @receiver ||= ReceiverFactory.build(element.receiver)
end