Class: Prism::StringQuery
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/prism/ffi.rb, lib/prism/string_query.rb, prism/extension.c |
Overview
Query methods that allow categorizing strings based on their context for where they could be valid in a Ruby syntax tree.
Class Method Summary
-
.constant?(string) ⇒ Boolean
Returns true if the string constitutes a valid constant name.
-
.local?(string) ⇒ Boolean
Returns true if the string constitutes a valid local variable name.
-
.method_name?(string) ⇒ Boolean
Mirrors the C extension’s .method_name? method.
-
.new(string) ⇒ StringQuery
constructor
Initialize a new query with the given string.
-
.query(result)
private
Parse the enum result and return an appropriate boolean.
Instance Attribute Summary
-
#constant? ⇒ Boolean
readonly
Whether or not this string is a valid constant name.
-
#local? ⇒ Boolean
readonly
Whether or not this string is a valid local variable name.
-
#method_name? ⇒ Boolean
readonly
Whether or not this string is a valid method name.
-
#string
readonly
The string that this query is wrapping.
Constructor Details
.new(string) ⇒ StringQuery
Initialize a new query with the given string.
Class Method Details
.constant?(string) ⇒ Boolean
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.
# File 'prism/extension.c', line 1181
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)); }
.local?(string) ⇒ Boolean
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.
# File 'prism/extension.c', line 1167
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)); }
.method_name?(string) ⇒ Boolean
Mirrors the C extension’s .method_name?
method.
# File 'prism/extension.c', line 1193
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)); }
.query(result) (private)
Parse the enum result and return an appropriate boolean.
# File 'lib/prism/ffi.rb', line 530
def query(result) case result when :PM_STRING_QUERY_ERROR raise ArgumentError, "Invalid or non ascii-compatible encoding" when :PM_STRING_QUERY_FALSE false when :PM_STRING_QUERY_TRUE true end end
Instance Attribute Details
#constant? ⇒ Boolean
(readonly)
Whether or not this string is a valid constant name.
#local? ⇒ Boolean
(readonly)
Whether or not this string is a valid local variable name.
#method_name? ⇒ Boolean
(readonly)
Whether or not this string is a valid method name.
# File 'lib/prism/string_query.rb', line 26
def method_name? StringQuery.method_name?(string) end
#string (readonly)
The string that this query is wrapping.
# File 'lib/prism/string_query.rb', line 8
attr_reader :string