Class: Solargraph::Pin::CompoundStatement
- Defined in:
- lib/solargraph/pin/compound_statement.rb
Overview
A series of statements where if a given statement executes, /all of the previous statements in the sequence must have executed as well/. In other words, the statements are run from the top in sequence, until interrupted by something like a return/break/next/raise/etc.
This mix-in is used in flow sensitive typing to determine how far we can assume a given assertion about a type can be trusted to be true.
Some examples in Ruby:
-
Bodies of methods and Ruby blocks
-
Branches of conditionals and loops - if/elsif/else, unless/else, when, until, ||=, ?:, switch/case/else
-
The body of begin-end/try/rescue/ensure statements
Compare/contrast with:
-
Scope - a sequence where variables declared are not available after the end of the scope. Note that this is not necessarily true for a compound statement.
-
Compound statement - synonym
-
Block - in Ruby this has a special meaning (a closure passed to a method), but in general parlance this is also a synonym.
-
Closure - a sequence which is also a scope
-
Namespace - a named sequence which is also a scope and a closure
See:
https://cse.buffalo.edu/~regan/cse305/RubyBNF.pdf
https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html
https://en.wikipedia.org/wiki/Block_(programming)
Note:
Just because statement #1 in a sequence is executed, it doesn’t mean that future ones will. Consider the effect of break/next/return/raise/etc. on control flow.
Constant Summary
Constants included from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Attributes inherited from Base
#code_object, #combine_priority, #directives, #docstring, #location, #name, #path, #return_type, #source, #type_location
Attributes included from Common
Instance Method Summary collapse
-
#initialize(node: nil, **splat) ⇒ CompoundStatement
constructor
A new instance of CompoundStatement.
Methods inherited from Base
#==, #all_location_text, #all_rooted?, #assert_location_provided, #assert_same, #assert_same_array_content, #assert_same_count, #assert_same_macros, #assert_source_provided, #best_location, #choose, #choose_longer, #choose_node, #choose_pin_attr, #choose_pin_attr_with_same_name, #choose_priority, #closure, #combine_closure, #combine_directives, #combine_name, #combine_return_type, #combine_with, #comments, #completion_item_kind, #deprecated?, #desc, #dodgy_return_type_source?, #erase_generics, #filename, #gates, #identity, #infer, #inner_desc, #inspect, #macros, #maybe_directives?, #nearly?, #needs_consistent_name?, #prefer_rbs_location, #presence_certain?, #probe, #probed?, #proxied?, #proxy, #rbs_location?, #realize, #reset_generated!, #resolve_generics, #resolve_generics_from_context, #symbol_kind, #to_rbs, #to_s, #transform_types, #type_desc, #typify, #variable?
Methods included from Logging
Methods included from Documenting
#documentation, normalize_indentation, strip_html_comments
Methods included from Conversions
#completion_item, #completion_item_kind, #deprecated?, #detail, #link_documentation, #probed?, #proxied?, #reset_conversions, #resolve_completion_item, #signature_help, #text_documentation
Methods included from Common
#binder, #closure, #closure=, #comments, #name, #namespace, #path, #reset_generated!, #return_type, #source
Constructor Details
#initialize(node: nil, **splat) ⇒ CompoundStatement
Returns a new instance of CompoundStatement.
49 50 51 52 |
# File 'lib/solargraph/pin/compound_statement.rb', line 49 def initialize node: nil, **splat super(**splat) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
45 46 47 |
# File 'lib/solargraph/pin/compound_statement.rb', line 45 def node @node end |