class Prism::StringQuery
我们将修补 StringQuery,以放入类级别的这些方法,从而保持一致的接口。
允许根据字符串在 Ruby 语法树中的上下文对其进行分类的查询方法。
属性
此查询正在包装的字符串。
Public Class Methods
Source
# File lib/prism/ffi.rb, line 554 def constant?(string) query(LibRubyParser.pm_string_query_constant(string, string.bytesize, string.encoding.name)) end
镜像 C 扩展的 StringQuery::constant? 方法。
Source
# File lib/prism/ffi.rb, line 549 def local?(string) query(LibRubyParser.pm_string_query_local(string, string.bytesize, string.encoding.name)) end
镜像 C 扩展的 StringQuery::local? 方法。
Source
# File lib/prism/ffi.rb, line 559 def method_name?(string) query(LibRubyParser.pm_string_query_method_name(string, string.bytesize, string.encoding.name)) end
镜像 C 扩展的 StringQuery::method_name? 方法。
Source
# File lib/prism/string_query.rb, line 12 def initialize(string) @string = string end
使用给定的字符串初始化一个新查询。
私有类方法
Source
# File lib/prism/ffi.rb, line 566 def query(result) case result when :PM_STRING_QUERY_ERROR raise ArgumentError, "Invalid or non ascii-compatible encoding" when :PM_STRING_QUERY_FALSE false when :PM_STRING_QUERY_TRUE true end end
解析枚举结果并返回适当的布尔值。
Public Instance Methods
Source
# File lib/prism/string_query.rb, line 22 def constant? StringQuery.constant?(string) end
此字符串是否是有效的常量名称。
Source
# File lib/prism/string_query.rb, line 17 def local? StringQuery.local?(string) end
此字符串是否是有效的局部变量名。
Source
# File lib/prism/string_query.rb, line 27 def method_name? StringQuery.method_name?(string) end
此字符串是否是有效的方法名称。