| 1 | # frozen_string_literal: true |
| 2 | # :markup: markdown |
| 3 | |
| 4 | module Prism |
| 5 | # Query methods that allow categorizing strings based on their context for |
| 6 | # where they could be valid in a Ruby syntax tree. |
| 7 | class StringQuery |
| 8 | # The string that this query is wrapping. |
| 9 | attr_reader :string |
| 10 | |
| 11 | # Initialize a new query with the given string. |
| 12 | def initialize(string) |
| 13 | @string = string |
| 14 | end |
| 15 | |
| 16 | # Whether or not this string is a valid local variable name. |
| 17 | def local? |
| 18 | StringQuery.local?(string) |
| 19 | end |
| 20 | |
| 21 | # Whether or not this string is a valid constant name. |
| 22 | def constant? |
| 23 | StringQuery.constant?(string) |
| 24 | end |
| 25 | |
| 26 | # Whether or not this string is a valid method name. |
| 27 | def method_name? |
| 28 | StringQuery.method_name?(string) |
| 29 | end |
| 30 | end |
| 31 | end |