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
The string that this query is wrapping.
Public Class Methods
(String string, ?version: String?) → bool
Source
static VALUE
string_query_constant_p(int argc, VALUE *argv, VALUE self) {
VALUE string;
const char *version = string_query_arguments(argc, argv, &string);
return string_query(pm_string_query_constant((const uint8_t *) RSTRING_PTR(string), RSTRING_LEN(string), rb_enc_get(string)->name, version), version);
}
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.
The version is the version of Ruby to answer for, as the version option of the parse methods reads it. It defaults to the nearest version to the running Ruby. Which letters begin a constant name depends on it.
(String string, ?version: String?) → bool
Source
static VALUE
string_query_keyword_p(int argc, VALUE *argv, VALUE self) {
VALUE string;
const char *version = string_query_arguments(argc, argv, &string);
return string_query(pm_string_query_keyword((const uint8_t *) RSTRING_PTR(string), RSTRING_LEN(string), rb_enc_get(string)->name, version), version);
}
Returns true if the string is a valid keyword, such as if, defined?, or __FILE__.
The version is the version of Ruby to answer for, as the version option of the parse methods reads it. It defaults to the nearest version to the running Ruby.
(String string, ?version: String?) → bool
Source
static VALUE
string_query_local_p(int argc, VALUE *argv, VALUE self) {
VALUE string;
const char *version = string_query_arguments(argc, argv, &string);
return string_query(pm_string_query_local((const uint8_t *) RSTRING_PTR(string), RSTRING_LEN(string), rb_enc_get(string)->name, version), version);
}
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.
The version is the version of Ruby to answer for, as the version option of the parse methods reads it. It defaults to the nearest version to the running Ruby.
(String string, ?version: String?) → bool
Source
static VALUE
string_query_method_name_p(int argc, VALUE *argv, VALUE self) {
VALUE string;
const char *version = string_query_arguments(argc, argv, &string);
return string_query(pm_string_query_method_name((const uint8_t *) RSTRING_PTR(string), RSTRING_LEN(string), rb_enc_get(string)->name, version), version);
}
Returns true if the string constitutes a valid method name.
The version is the version of Ruby to answer for, as the version option of the parse methods reads it. It defaults to the nearest version to the running Ruby.
(String string) → void
Source
# File lib/prism/string_query.rb, line 26 def initialize(string) @string = string end
Initialize a new query with the given string.
Public Instance Methods
(?version: String?) → bool
Source
# File lib/prism/string_query.rb, line 40 def constant?(version: nil) StringQuery.constant?(string, version: version) end
Whether or not this string is a valid constant name.
(?version: String?) → bool
Source
# File lib/prism/string_query.rb, line 54 def keyword?(version: nil) StringQuery.keyword?(string, version: version) end
Whether or not this string is a valid keyword.
(?version: String?) → bool
Source
# File lib/prism/string_query.rb, line 33 def local?(version: nil) StringQuery.local?(string, version: version) end
Whether or not this string is a valid local variable name.
(?version: String?) → bool
Source
# File lib/prism/string_query.rb, line 47 def method_name?(version: nil) StringQuery.method_name?(string, version: version) end
Whether or not this string is a valid method name.