Class: NScript::ObjectNode
Constant Summary
Constants inherited from Node
Instance Method Summary collapse
- #compile_node(o) ⇒ Object
-
#initialize(properties = []) ⇒ ObjectNode
constructor
A new instance of ObjectNode.
Methods inherited from Node
#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write
Constructor Details
#initialize(properties = []) ⇒ ObjectNode
Returns a new instance of ObjectNode.
633 634 635 |
# File 'lib/nscript/parser/nodes.rb', line 633 def initialize(properties = []) @properties = properties end |
Instance Method Details
#compile_node(o) ⇒ Object
637 638 639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/nscript/parser/nodes.rb', line 637 def compile_node(o) o[:indent] = idt(1) joins = Hash.new("\n") non_comments = @properties.select {|p| !p.is_a?(CommentNode) } non_comments.each {|p| joins[p] = p == non_comments.last ? "\n" : ",\n" } props = @properties.map { |prop| join = joins[prop] join = '' if prop == @properties.last indent = prop.is_a?(CommentNode) ? '' : idt(1) "#{indent}#{prop.compile(o)}#{join}" }.join('') write("{\n#{props}\n#{idt}}") end |