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.
12 13 14 |
# File 'lib/prism/string_query.rb', line 12 def initialize(string) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
The string that this query is wrapping.
9 10 11 |
# File 'lib/prism/string_query.rb', line 9 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.
546 547 548 |
# File 'lib/prism/ffi.rb', line 546 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.
541 542 543 |
# File 'lib/prism/ffi.rb', line 541 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.
551 552 553 |
# File 'lib/prism/ffi.rb', line 551 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.
22 23 24 |
# File 'lib/prism/string_query.rb', line 22 def constant? StringQuery.constant?(string) end |
#local? ⇒ Boolean
Whether or not this string is a valid local variable name.
17 18 19 |
# File 'lib/prism/string_query.rb', line 17 def local? StringQuery.local?(string) end |
#method_name? ⇒ Boolean
Whether or not this string is a valid method name.
27 28 29 |
# File 'lib/prism/string_query.rb', line 27 def method_name? StringQuery.method_name?(string) end |