class Prism::StringQuery - Documentation for Ruby 4.1
Description: class Prism::StringQuery: Query methods that allow categorizing strings based on their context for where they could be valid in a Ruby syntax tree.
Keywords: ruby,class,Prism::StringQuery

🔍

No recent searches

# class Prism::StringQuery

Query methods that allow categorizing strings based on their context for where they could be valid in a Ruby syntax tree.

### Attributes

string [R]

The string that this query is wrapping.

### Public Class Methods

constant?(string) → bool
Source

    static VALUE
    string_query_constant_p(VALUE self, VALUE string) {
        const uint8_t *source = (const uint8_t *) check_string(string);
        return string_query(pm_string_query_constant(source, RSTRING_LEN(string), rb_enc_get(string)->name));
    }

Returns true if the string constitutes a valid constant name. Note that this means the names that can be set through `Module#const_set`, not necessarily the ones that can be set through a constant assignment.

local?(string) → bool
Source

    static VALUE
    string_query_local_p(VALUE self, VALUE string) {
        const uint8_t *source = (const uint8_t *) check_string(string);
        return string_query(pm_string_query_local(source, RSTRING_LEN(string), rb_enc_get(string)->name));
    }

Returns true if the string constitutes a valid local variable name. Note that this means the names that can be set through `Binding#local_variable_set`, not necessarily the ones that can be set through a local variable assignment.

method_name?(string) → bool
Source

    static VALUE
    string_query_method_name_p(VALUE self, VALUE string) {
        const uint8_t *source = (const uint8_t *) check_string(string);
        return string_query(pm_string_query_method_name(source, RSTRING_LEN(string), rb_enc_get(string)->name));
    }

Returns true if the string constitutes a valid method name.

new (string)
Source

    # File lib/prism/string_query.rb, line 21
    def initialize(string)
      @string = string
    end

Initialize a new query with the given string.

### Public Instance Methods

constant? ()
Source

    # File lib/prism/string_query.rb, line 35
    def constant?
      StringQuery.constant?(string)
    end

Whether or not this string is a valid constant name.

local? ()
Source

    # File lib/prism/string_query.rb, line 28
    def local?
      StringQuery.local?(string)
    end

Whether or not this string is a valid local variable name.

method_name? ()
Source

    # File lib/prism/string_query.rb, line 42
    def method_name?
      StringQuery.method_name?(string)
    end

Whether or not this string is a valid method name.