Class: CodeBreaker::Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CodeBreaker::Parsable::Node

#method_missing, #not_implemented_message, #parse, #parse_as_hash, #parse_as_last_child_hash, #parse_as_node_type, #parse_children

Constructor Details

#initialize(code) ⇒ Parser

Returns a new instance of Parser.



17
18
19
# File 'lib/code_breaker/parser.rb', line 17

def initialize(code)
  @input = code.to_s.strip
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CodeBreaker::Parsable::Node

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



15
16
17
# File 'lib/code_breaker/parser.rb', line 15

def input
  @input
end

Instance Method Details

#runObject Also known as: output



21
22
23
24
25
26
27
28
# File 'lib/code_breaker/parser.rb', line 21

def run
  unless @output
    ast = ::Parser::CurrentRuby.parse(input)
    @output = ast.nil? ? [] : parse(ast.loc.node)
  end

  @output
end