class RuboCop::AST::PairNode

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

Constants

COLON
HASH_ROCKET
SPACED_COLON
SPACED_HASH_ROCKET

Public Instance Methods

colon?() click to toggle source

Checks whether the `pair` uses a colon delimiter.

@return [Boolean] whether this `pair` uses a colon delimiter

# File lib/rubocop/ast/node/pair_node.rb, line 26
def colon?
  loc.operator.is?(COLON)
end
delimiter(with_spacing = false) click to toggle source

Returns the delimiter of the `pair` as a string. Returns `=>` for a colon delimited `pair`, and `:` for a hash rocket delimited `pair`.

@param [Boolean] with_spacing whether to include spacing @return [String] the delimiter of the `pair`

# File lib/rubocop/ast/node/pair_node.rb, line 35
def delimiter(with_spacing = false)
  if with_spacing
    hash_rocket? ? SPACED_HASH_ROCKET : SPACED_COLON
  else
    hash_rocket? ? HASH_ROCKET : COLON
  end
end
hash_rocket?() click to toggle source

Checks whether the `pair` uses a hash rocket delimiter.

@return [Boolean] whether this `pair` uses a hash rocket delimiter

# File lib/rubocop/ast/node/pair_node.rb, line 19
def hash_rocket?
  loc.operator.is?(HASH_ROCKET)
end
inverse_delimiter(with_spacing = false) click to toggle source

Returns the inverse delimiter of the `pair` as a string.

@param [Boolean] with_spacing whether to include spacing @return [String] the inverse delimiter of the `pair`

# File lib/rubocop/ast/node/pair_node.rb, line 47
def inverse_delimiter(with_spacing = false)
  if with_spacing
    hash_rocket? ? SPACED_COLON : SPACED_HASH_ROCKET
  else
    hash_rocket? ? COLON : HASH_ROCKET
  end
end
node_parts() click to toggle source

Custom destructuring method. This is used to normalize the branches for `pair` and `kwsplat` nodes, to add duck typing to `hash` elements.

@return [Array<Node>] the different parts of the `pair`

# File lib/rubocop/ast/node/pair_node.rb, line 59
def node_parts
  to_a
end