Class: Prism::StringQuery

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ StringQuery

Initialize a new query with the given string.



11
12
13
# File 'lib/prism/string_query.rb', line 11

def initialize(string)
  @string = string
end

Instance Attribute Details

#stringObject (readonly)

The string that this query is wrapping.



8
9
10
# File 'lib/prism/string_query.rb', line 8

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.

Returns:

  • (Boolean)


518
519
520
# File 'lib/prism/ffi.rb', line 518

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.

Returns:

  • (Boolean)


513
514
515
# File 'lib/prism/ffi.rb', line 513

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.

Returns:

  • (Boolean)


523
524
525
# File 'lib/prism/ffi.rb', line 523

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.

Returns:

  • (Boolean)


21
22
23
# File 'lib/prism/string_query.rb', line 21

def constant?
  StringQuery.constant?(string)
end

#local?Boolean

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

Returns:

  • (Boolean)


16
17
18
# File 'lib/prism/string_query.rb', line 16

def local?
  StringQuery.local?(string)
end

#method_name?Boolean

Whether or not this string is a valid method name.

Returns:

  • (Boolean)


26
27
28
# File 'lib/prism/string_query.rb', line 26

def method_name?
  StringQuery.method_name?(string)
end