summaryrefslogtreecommitdiff
path: root/lib/prism/string_query.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/prism/string_query.rb')
-rw-r--r--lib/prism/string_query.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/prism/string_query.rb b/lib/prism/string_query.rb
new file mode 100644
index 0000000000..547f58d2fa
--- /dev/null
+++ b/lib/prism/string_query.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+# :markup: markdown
+
+module Prism
+ # Query methods that allow categorizing strings based on their context for
+ # where they could be valid in a Ruby syntax tree.
+ class StringQuery
+ # The string that this query is wrapping.
+ attr_reader :string
+
+ # Initialize a new query with the given string.
+ def initialize(string)
+ @string = string
+ end
+
+ # Whether or not this string is a valid local variable name.
+ def local?
+ StringQuery.local?(string)
+ end
+
+ # Whether or not this string is a valid constant name.
+ def constant?
+ StringQuery.constant?(string)
+ end
+
+ # Whether or not this string is a valid method name.
+ def method_name?
+ StringQuery.method_name?(string)
+ end
+ end
+end