class RuboCop::Cop::Style::CharacterLiteral

“C-M-d” # same as above
?C-M-d
# good - control & meta escapes
’x’
# good
?x
# bad
@example
That’s a good use case of ? literal so it doesn’t count it as an offense.
? character literal can be used to express meta and control character.
is mostly redundant at this point.
essentially one-character strings, so this syntax
Starting with Ruby 1.9 character literals are
Checks for uses of the character literal ?x.

def autocorrect(corrector, node)

def autocorrect(corrector, node)
  string = node.source[1..]
  # special character like \n
  # or ' which needs to use "" or be escaped.
  if string.length == 2 || string == "'"
    corrector.replace(node, %("#{string}"))
  elsif string.length == 1 # normal character
    corrector.replace(node, "'#{string}'")
  end
end

def correct_style_detected; end

called from StringHelp.
Dummy implementation of method in ConfigurableEnforcedStyle that is
def correct_style_detected; end

def offense?(node)

def offense?(node)
  # we don't register an offense for things like ?\C-\M-d
  node.character_literal? && node.source.size.between?(2, 3)
end

def opposite_style_detected; end

called from StringHelp.
Dummy implementation of method in ConfigurableEnforcedStyle that is
def opposite_style_detected; end