Class: Fastererer::MethodCall
- Inherits:
-
Object
- Object
- Fastererer::MethodCall
- Defined in:
- lib/fastererer/method_call.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
Class Method Summary collapse
Instance Method Summary collapse
- #arguments ⇒ Object
- #block? ⇒ Boolean
- #block_argument_names ⇒ Object
- #block_body ⇒ Object
-
#hash? ⇒ Boolean
Provably a Hash: bare ‘Hash.new`/`Hash` (any args — every `Hash` yields a Hash), not qualified `Foo::Hash`.
-
#initialize(node) ⇒ MethodCall
constructor
A new instance of MethodCall.
- #lambda_literal? ⇒ Boolean
- #method_name ⇒ Object
- #name ⇒ Object
- #receiver ⇒ Object
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
#element ⇒ Object (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
#arguments ⇒ Object
29 30 31 |
# File 'lib/fastererer/method_call.rb', line 29 def arguments @arguments ||= argument_nodes.map { |argument| Argument.new(argument) } end |
#block? ⇒ Boolean
41 42 43 |
# File 'lib/fastererer/method_call.rb', line 41 def block? !block_node.nil? end |
#block_argument_names ⇒ Object
37 38 39 |
# File 'lib/fastererer/method_call.rb', line 37 def block_argument_names @block_argument_names ||= positional_block_parameter_names end |
#block_body ⇒ Object
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.
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
45 46 47 |
# File 'lib/fastererer/method_call.rb', line 45 def lambda_literal? false end |
#method_name ⇒ Object
21 22 23 |
# File 'lib/fastererer/method_call.rb', line 21 def method_name element.name end |
#name ⇒ Object
25 26 27 |
# File 'lib/fastererer/method_call.rb', line 25 def name method_name end |
#receiver ⇒ Object
17 18 19 |
# File 'lib/fastererer/method_call.rb', line 17 def receiver @receiver ||= ReceiverFactory.build(element.receiver) end |