class DissociatedIntrospection::RubyCode
Attributes
ast[R]
comments[R]
Public Class Methods
build_from_ast(ast, comments: [])
click to toggle source
@param [Ast] ast @param [Array] comments @return [DissociatedIntrospection::RubyCode]
# File lib/dissociated_introspection/ruby_code.rb, line 17 def self.build_from_ast(ast, comments: []) new(source: nil, ast: ast, comments: comments ) end
build_from_source(source, parse_with_comments: false)
click to toggle source
@param [String] source @param [true, false] parse_with_comments @return [DissociatedIntrospection::RubyCode]
# File lib/dissociated_introspection/ruby_code.rb, line 7 def self.build_from_source(source, parse_with_comments: false) ast, comments = create_ast(parse_with_comments, source) new(source: source, ast: ast, comments: comments) end
create_ast(parse_with_comments, source)
click to toggle source
@private
# File lib/dissociated_introspection/ruby_code.rb, line 30 def self.create_ast(parse_with_comments, source) a = Parser::CurrentRuby.public_send(self.parse_source_method(parse_with_comments), source) if parse_with_comments [a[0], a[1]] else [a, []] end end
new(source:, ast:, comments:)
click to toggle source
@private
# File lib/dissociated_introspection/ruby_code.rb, line 41 def initialize(source:, ast:, comments:) @source = source @ast = ast @comments = comments end
parse_source_method(parse_with_comments)
click to toggle source
@private
# File lib/dissociated_introspection/ruby_code.rb, line 25 def self.parse_source_method(parse_with_comments) parse_with_comments ? :parse_with_comments : :parse end
Public Instance Methods
comments?()
click to toggle source
# File lib/dissociated_introspection/ruby_code.rb, line 47 def comments? !comments.empty? end
source()
click to toggle source
@return [String]
# File lib/dissociated_introspection/ruby_code.rb, line 52 def source @source = @source.nil? ? source_from_ast : @source end
Also aliased as: to_s
source_from_ast()
click to toggle source
@return [String]
# File lib/dissociated_introspection/ruby_code.rb, line 58 def source_from_ast Unparser.unparse(ast, comments) end