List of all magic instructions in Ruby

Viewed 64

I am looking for a list of all the magic instructions in Ruby.

For example:

#!/usr/bin/ruby -w
# encoding: windows-1252
# warn_indent: false
# frozen_string_literal: true

I just got one link mentioning some of them.

1 Answers

The link you mention there has a link to the Ruby source where these are defined:

static const struct magic_comment magic_comments[] = {
    {"coding", magic_comment_encoding, parser_encode_length},
    {"encoding", magic_comment_encoding, parser_encode_length},
    {"frozen_string_literal", parser_set_compile_option_flag},
    {"warn_indent", parser_set_token_info},
# if WARN_PAST_SCOPE
    {"warn_past_scope", parser_set_past_scope},
# endif
};

One of these is gated based on a #define, so it may be a feature that's incomplete or yet to ship, perhaps held back for Ruby 2.7 or 3.0.

Related