class RuboCop::MagicComment::SimpleComment

Wrapper for regular magic comments not bound to an editor.

Simple comments can only specify one setting per comment.

@example frozen string literal comments

comment1 = RuboCop::MagicComment.parse('# frozen_string_literal: true')
comment1.frozen_string_literal # => true
comment1.encoding              # => nil

@example encoding comments

comment2 = RuboCop::MagicComment.parse('# encoding: utf-8')
comment2.frozen_string_literal # => nil
comment2.encoding              # => 'utf-8'

Public Instance Methods

encoding() click to toggle source

Match `encoding` or `coding`

# File lib/rubocop/magic_comment.rb, line 192
def encoding
  extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/i)
end

Private Instance Methods

extract_frozen_string_literal() click to toggle source

Extract `frozen_string_literal`.

The `frozen_string_literal` magic comment only works if it is the only text in the comment.

Case-insensitive and dashes/underscores are acceptable. @see git.io/vM7Mg

# File lib/rubocop/magic_comment.rb, line 205
def extract_frozen_string_literal
  extract(/\A\s*#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/i)
end