Class: Prism::StringQuery
- Inherits:
-
Object
- Object
- Prism::StringQuery
- Defined in:
- lib/prism/ffi.rb,
lib/prism/string_query.rb,
sig/generated/prism/string_query.rbs,
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 ⇒ String
readonly
The string that this query is wrapping.
Class Method Summary collapse
-
.constant?(string) ⇒ Boolean
:markup: markdown call-seq: constant?(string) -> bool.
-
.keyword?(string) ⇒ Boolean
:markup: markdown call-seq: keyword?(string) -> bool.
-
.local?(string) ⇒ Boolean
:markup: markdown call-seq: local?(string) -> bool.
-
.method_name?(string) ⇒ Boolean
:markup: markdown call-seq: method_name?(string) -> bool.
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.
-
#keyword? ⇒ Boolean
Whether or not this string is a valid keyword.
-
#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.
: (String string) -> void
22 23 24 |
# File 'lib/prism/string_query.rb', line 22 def initialize(string) @string = string end |
Instance Attribute Details
#string ⇒ String (readonly)
The string that this query is wrapping.
17 18 19 |
# File 'lib/prism/string_query.rb', line 17 def string @string end |
Class Method Details
.constant?(string) ⇒ Boolean
:markup: markdown call-seq:
constant?(string) -> bool
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.
717 718 719 |
# File 'lib/prism/ffi.rb', line 717 def constant?(string) query(LibRubyParser.pm_string_query_constant(string, string.bytesize, string.encoding.name)) end |
.keyword?(string) ⇒ Boolean
:markup: markdown call-seq:
keyword?(string) -> bool
Returns true if the string is a valid keyword, such as if, defined?, or
__FILE__.
727 728 729 |
# File 'lib/prism/ffi.rb', line 727 def keyword?(string) query(LibRubyParser.pm_string_query_keyword(string, string.bytesize, string.encoding.name)) end |
.local?(string) ⇒ Boolean
:markup: markdown call-seq:
local?(string) -> bool
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.
712 713 714 |
# File 'lib/prism/ffi.rb', line 712 def local?(string) query(LibRubyParser.pm_string_query_local(string, string.bytesize, string.encoding.name)) end |
.method_name?(string) ⇒ Boolean
:markup: markdown call-seq:
method_name?(string) -> bool
Returns true if the string constitutes a valid method name.
722 723 724 |
# File 'lib/prism/ffi.rb', line 722 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.
: () -> bool
36 37 38 |
# File 'lib/prism/string_query.rb', line 36 def constant? StringQuery.constant?(string) end |
#keyword? ⇒ Boolean
Whether or not this string is a valid keyword.
: () -> bool
50 51 52 |
# File 'lib/prism/string_query.rb', line 50 def keyword? StringQuery.keyword?(string) end |
#local? ⇒ Boolean
Whether or not this string is a valid local variable name.
: () -> bool
29 30 31 |
# File 'lib/prism/string_query.rb', line 29 def local? StringQuery.local?(string) end |
#method_name? ⇒ Boolean
Whether or not this string is a valid method name.
: () -> bool
43 44 45 |
# File 'lib/prism/string_query.rb', line 43 def method_name? StringQuery.method_name?(string) end |