Module: RuboCop::AST::ConditionalNode
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubocop/ast/node/mixin/conditional_node.rb |
Overview
Common functionality for nodes that have conditions:
if
, while
, until
, case
.
This currently doesn’t include when
nodes, because they have multiple
conditions, and need to be checked for that.
Instance Attribute Summary
-
#multiline_condition? ⇒ Boolean
readonly
Checks whether the condition of the node is written on more than one line.
-
#single_line_condition? ⇒ Boolean
readonly
Checks whether the condition of the node is written on a single line.
Instance Method Summary
-
#body ⇒ Node?
Returns the body associated with the condition.
-
#condition ⇒ Node?
Returns the condition of the node.
Instance Attribute Details
#multiline_condition? ⇒ Boolean
(readonly)
Checks whether the condition of the node is written on more than one line.
# File 'lib/rubocop/ast/node/mixin/conditional_node.rb', line 21
def multiline_condition? !single_line_condition? end
#single_line_condition? ⇒ Boolean
(readonly)
Checks whether the condition of the node is written on a single line.
# File 'lib/rubocop/ast/node/mixin/conditional_node.rb', line 13
def single_line_condition? loc.keyword.line == condition.source_range.line end
Instance Method Details
#body ⇒ Node?
For if
nodes, this is the truthy branch.
Returns the body associated with the condition. This works together with each node’s custom destructuring method to select the correct part of the node.
# File 'lib/rubocop/ast/node/mixin/conditional_node.rb', line 40
def body node_parts[1] end
#condition ⇒ Node?
Returns the condition of the node. This works together with each node’s custom destructuring method to select the correct part of the node.
# File 'lib/rubocop/ast/node/mixin/conditional_node.rb', line 29
def condition node_parts[0] end