Class: RuboCop::AST::ArrayNode

Inherits:
Node
  • Object
show all
Defined in:
lib/rubocop/ast/node/array_node.rb

Overview

A node extension for ‘array` nodes. This will be used in place of a plain node when the builder constructs the AST, making its methods available to all `array` nodes within RuboCop.

Constant Summary collapse

PERCENT_LITERAL_TYPES =
{
  string: /^%[wW]/,
  symbol: /^%[iI]/
}.freeze

Constants inherited from Node

Node::BASIC_LITERALS, Node::COMPARISON_OPERATORS, Node::COMPOSITE_LITERALS, Node::FALSEY_LITERALS, Node::IMMUTABLE_LITERALS, Node::KEYWORDS, Node::LITERALS, Node::MUTABLE_LITERALS, Node::OPERATOR_KEYWORDS, Node::REFERENCES, Node::SPECIAL_KEYWORDS, Node::TRUTHY_LITERALS, Node::VARIABLES

Instance Method Summary collapse

Methods inherited from Node

#ancestors, #argument?, #asgn_method_call?, #basic_literal?, #binary_operation?, #chained?, #child_nodes, #complete!, #complete?, #const_name, def_matcher, #defined_module, #defined_module_name, #descendants, #each_ancestor, #each_child_node, #each_descendant, #each_node, #falsey_literal?, #immutable_literal?, #initialize, #keyword?, #keyword_bang?, #keyword_not?, #literal?, #multiline?, #mutable_literal?, #numeric_type?, #parent, #parent_module_name, #pure?, #receiver, #reference?, #sibling_index, #single_line?, #source, #source_range, #special_keyword?, #truthy_literal?, #unary_operation?, #updated, #value_used?, #variable?

Methods included from Sexp

#s

Constructor Details

This class inherits a constructor from RuboCop::AST::Node

Instance Method Details

#percent_literal?Boolean #percent_literal?(type) ⇒ Boolean

Checks whether the ‘array` literal is delimited by percent brackets.

Overloads:

  • #percent_literal?Boolean

    Check for any percent literal.

  • #percent_literal?(type) ⇒ Boolean

    Check for percent literaly of type ‘type`.

Parameters:

  • type (Symbol) (defaults to: nil)

    an optional percent literal type

Returns:

  • (Boolean)

    whether the array is enclosed in percent brackets



36
37
38
39
40
41
42
# File 'lib/rubocop/ast/node/array_node.rb', line 36

def percent_literal?(type = nil)
  if type
    loc.begin && loc.begin.source =~ PERCENT_LITERAL_TYPES[type]
  else
    loc.begin && loc.begin.source.start_with?('%')
  end
end

#square_brackets?Boolean

Checks whether the ‘array` literal is delimited by square brackets.

Returns:

  • (Boolean)

    whether the array is enclosed in square brackets



24
25
26
# File 'lib/rubocop/ast/node/array_node.rb', line 24

def square_brackets?
  loc.begin && loc.begin.is?('[')
end

#valuesArray<Node>

Returns an array of all value nodes in the ‘array` literal.

Returns:

  • (Array<Node>)

    an array of value nodes



17
18
19
# File 'lib/rubocop/ast/node/array_node.rb', line 17

def values
  each_child_node.to_a
end