class Prism::Result
这表示调用 ::parse 或 ::parse_file 的结果。它包含请求的结构、遇到的任何注释以及遇到的任何错误。
属性
解析期间遇到的注释列表。
一个可选的位置,表示 __END__ 标记的位置以及文件的其余内容。当被解析的文件是正在执行的主文件时,此内容将加载到 DATA 常量中。
解析期间生成的错误列表。
解析期间遇到的魔法注释列表。
一个 Source
实例,表示被解析的源代码。
解析期间生成的警告列表。
公共类方法
源代码
# File lib/prism/parse_result.rb, line 684 def initialize(comments, magic_comments, data_loc, errors, warnings, source) @comments = comments @magic_comments = magic_comments @data_loc = data_loc @errors = errors @warnings = warnings @source = source end
使用给定值创建一个新的结果对象。
公共实例方法
源代码
# File lib/prism/parse_result.rb, line 716 def code_units_cache(encoding) source.code_units_cache(encoding) end
为给定的编码创建代码单元缓存。
源代码
# File lib/prism/parse_result.rb, line 694 def deconstruct_keys(keys) { comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings } end
为 Result
实现哈希模式匹配接口。
源代码
# File lib/prism/parse_result.rb, line 699 def encoding source.encoding end
返回被解析的源代码的编码。
源代码
# File lib/prism/parse_result.rb, line 711 def failure? !success? end
如果在解析过程中出现错误则返回 true,如果没有则返回 false。
源代码
# File lib/prism/parse_result.rb, line 705 def success? errors.empty? end
如果在解析过程中没有错误则返回 true,如果有则返回 false。