Class: Henitai::Operators::BooleanLiteral

Inherits:
Henitai::Operator show all
Defined in:
lib/henitai/operators/boolean_literal.rb

Overview

Toggles boolean literals and removes unary negation.

Constant Summary collapse

NODE_TYPES =
%i[true false send].freeze

Constants inherited from Henitai::Operator

Henitai::Operator::FULL_SET, Henitai::Operator::LIGHT_SET

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Henitai::Operator

for_set, #name

Class Method Details

.node_typesObject



11
12
13
# File 'lib/henitai/operators/boolean_literal.rb', line 11

def self.node_types
  NODE_TYPES
end

Instance Method Details

#mutate(node, subject:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/henitai/operators/boolean_literal.rb', line 15

def mutate(node, subject:)
  # Parser uses :true / :false node types, so the AST symbols are intentional.
  # rubocop:disable Lint/BooleanSymbol
  case node.type
  when :true
    [mutate_true_literal(node, subject:)]
  when :false
    [mutate_false_literal(node, subject:)]
  when :send
    mutate_negation(node, subject:)
  else
    []
  end
  # rubocop:enable Lint/BooleanSymbol
end