Class: RuboCop::Cop::SpaceInside::Brackets

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/mixin/space_inside.rb

Overview

Wraps info about the brackets. Makes it easy to check whether a token is one of the brackets.

Examples:

Parentheses ‘()`

Brackets.new(:tLPAREN, :tRPAREN, 'parentheses')

Square brackets ‘[]`

Brackets.new([:tLBRACK, :tLBRACK2], :tRBRACK, 'square brackets')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right, kind) ⇒ Brackets

Returns a new instance of Brackets.



61
62
63
64
65
# File 'lib/rubocop/cop/mixin/space_inside.rb', line 61

def initialize(left, right, kind)
  @left_side_types = [left].flatten
  @right_side_type = right
  @kind = kind
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



59
60
61
# File 'lib/rubocop/cop/mixin/space_inside.rb', line 59

def kind
  @kind
end

Instance Method Details

#left_side?(token) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/rubocop/cop/mixin/space_inside.rb', line 67

def left_side?(token)
  # Left side bracket has to be able to match multiple types
  # (e.g. :tLBRACK and :tLBRACK2)
  @left_side_types.include?(token.type)
end

#right_side?(token) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/rubocop/cop/mixin/space_inside.rb', line 73

def right_side?(token)
  @right_side_type == token.type
end