class Prism::StringQuery

Here we are going to patch StringQuery to put in the class-level methods so that it can maintain a consistent interface

Query methods that allow categorizing strings based on their context for where they could be valid in a Ruby syntax tree.

Attributes

string [R]

The string that this query is wrapping.

Public Class Methods

constant? (string)

Mirrors the C extension’s StringQuery::constant? method.

# File lib/prism/ffi.rb, line 510
def constant?(string)
  query(LibRubyParser.pm_string_query_constant(string, string.bytesize, string.encoding.name))
end
local? (string)

Mirrors the C extension’s StringQuery::local? method.

# File lib/prism/ffi.rb, line 505
def local?(string)
  query(LibRubyParser.pm_string_query_local(string, string.bytesize, string.encoding.name))
end
method_name? (string)

Mirrors the C extension’s StringQuery::method_name? method.

# File lib/prism/ffi.rb, line 515
def method_name?(string)
  query(LibRubyParser.pm_string_query_method_name(string, string.bytesize, string.encoding.name))
end
new (string)

Initialize a new query with the given string.

# File lib/prism/string_query.rb, line 11
def initialize(string)
  @string = string
end

Public Instance Methods

constant? ()

Whether or not this string is a valid constant name.

# File lib/prism/string_query.rb, line 21
def constant?
  StringQuery.constant?(string)
end
local? ()

Whether or not this string is a valid local variable name.

# File lib/prism/string_query.rb, line 16
def local?
  StringQuery.local?(string)
end
method_name? ()

Whether or not this string is a valid method name.

# File lib/prism/string_query.rb, line 26
def method_name?
  StringQuery.method_name?(string)
end