Class: Prism::StringQuery
- Inherits:
-
Object
- Object
- Prism::StringQuery
- Defined in:
- lib/prism/ffi.rb,
lib/prism/string_query.rb,
ext/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.
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
The string that this query is wrapping.
Class Method Summary collapse
-
.Prism::StringQuery::constant?(string) ⇒ Boolean
Returns true if the string constitutes a valid constant name.
-
.Prism::StringQuery::local?(string) ⇒ Boolean
Returns true if the string constitutes a valid local variable name.
-
.Prism::StringQuery::method_name?(string) ⇒ Boolean
Returns true if the string constitutes a valid method name.
Instance Method Summary collapse
-
#constant? ⇒ Boolean
Whether or not this string is a valid constant name.
-
#initialize(string) ⇒ StringQuery
constructor
Initialize a new query with the given string.
-
#local? ⇒ Boolean
Whether or not this string is a valid local variable name.
-
#method_name? ⇒ Boolean
Whether or not this string is a valid method name.
Constructor Details
#initialize(string) ⇒ StringQuery
Initialize a new query with the given string.
11 12 13 |
# File 'lib/prism/string_query.rb', line 11 def initialize(string) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
The string that this query is wrapping.
8 9 10 |
# File 'lib/prism/string_query.rb', line 8 def string @string end |
Class Method Details
.Prism::StringQuery::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.
518 519 520 |
# File 'lib/prism/ffi.rb', line 518 def constant?(string) query(LibRubyParser.pm_string_query_constant(string, string.bytesize, string.encoding.name)) end |
.Prism::StringQuery::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.
513 514 515 |
# File 'lib/prism/ffi.rb', line 513 def local?(string) query(LibRubyParser.pm_string_query_local(string, string.bytesize, string.encoding.name)) end |
.Prism::StringQuery::method_name?(string) ⇒ Boolean
Returns true if the string constitutes a valid method name.
523 524 525 |
# File 'lib/prism/ffi.rb', line 523 def method_name?(string) query(LibRubyParser.pm_string_query_method_name(string, string.bytesize, string.encoding.name)) end |
Instance Method Details
#constant? ⇒ Boolean
Whether or not this string is a valid constant name.
21 22 23 |
# File 'lib/prism/string_query.rb', line 21 def constant? StringQuery.constant?(string) end |
#local? ⇒ Boolean
Whether or not this string is a valid local variable name.
16 17 18 |
# File 'lib/prism/string_query.rb', line 16 def local? StringQuery.local?(string) end |
#method_name? ⇒ Boolean
Whether or not this string is a valid method name.
26 27 28 |
# File 'lib/prism/string_query.rb', line 26 def method_name? StringQuery.method_name?(string) end |