Class: Prism::Merge::BlockBinding
- Inherits:
-
Object
- Object
- Prism::Merge::BlockBinding
- Defined in:
- lib/prism/merge/block_binding.rb
Overview
Finds a simple block parameter on a structurally identified call.
Instance Attribute Summary collapse
-
#call ⇒ Object
readonly
Returns the value of attribute call.
-
#parameter ⇒ Object
readonly
Returns the value of attribute parameter.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(call:, parameter:) ⇒ BlockBinding
constructor
A new instance of BlockBinding.
- #name ⇒ Object
- #scope_range ⇒ Object
Constructor Details
#initialize(call:, parameter:) ⇒ BlockBinding
Returns a new instance of BlockBinding.
9 10 11 12 |
# File 'lib/prism/merge/block_binding.rb', line 9 def initialize(call:, parameter:) @call = call @parameter = parameter end |
Instance Attribute Details
#call ⇒ Object (readonly)
Returns the value of attribute call.
7 8 9 |
# File 'lib/prism/merge/block_binding.rb', line 7 def call @call end |
#parameter ⇒ Object (readonly)
Returns the value of attribute parameter.
7 8 9 |
# File 'lib/prism/merge/block_binding.rb', line 7 def parameter @parameter end |
Class Method Details
.find(source, &matcher) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/prism/merge/block_binding.rb', line 22 def self.find(source, &matcher) parse_result = TreeHaver.with_backend(Prism::Merge::BACKEND_REFERENCE.id) do TreeHaver.parser_for(:ruby, backend_type: :prism).parse(source).parse_result end return unless parse_result.success? call = parse_result.value.breadth_first_search_all { |node| node.is_a?(::Prism::CallNode) }.find(&matcher) parameter = call&.block&.parameters&.parameters&.requireds&.first new(call: call, parameter: parameter) if parameter end |
Instance Method Details
#name ⇒ Object
14 15 16 |
# File 'lib/prism/merge/block_binding.rb', line 14 def name parameter.name.to_s end |
#scope_range ⇒ Object
18 19 20 |
# File 'lib/prism/merge/block_binding.rb', line 18 def scope_range call.block.location.start_offset...call.block.location.end_offset end |