Module: CodeBreaker::Parsable::Assignments

Includes:
Node
Included in:
CodeBreaker::Parser
Defined in:
lib/code_breaker/parsable/assignments.rb

Instance Method Summary collapse

Methods included from Node

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

Dynamic Method Handling

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

Instance Method Details

#parse_casgn_node(node) ⇒ Object

constant assignment



41
42
43
44
45
46
47
# File 'lib/code_breaker/parsable/assignments.rb', line 41

def parse_casgn_node(node)
  name     = node.children[1]
  children = node.children[2]
  value    = children.nil? ? name : [name, parse(node.children[2])]

  { node.type => value }
end

#parse_masgn_node(node) ⇒ Object

multiple assignment



28
29
30
31
32
33
# File 'lib/code_breaker/parsable/assignments.rb', line 28

def parse_masgn_node(node)
  lhs, rhs = parse_children(node)
  values   = multiple_assignment_values(lhs, rhs)

  { node.type => { lhs => values } }
end

#parse_mlhs_node(node) ⇒ Object

multiple left hand side



36
37
38
# File 'lib/code_breaker/parsable/assignments.rb', line 36

def parse_mlhs_node(node)
  parse_children(node).map(&:values).flatten
end