Class: Twostroke::AST::ObjectLiteral

Inherits:
Base
  • Object
show all
Defined in:
lib/twostroke/ast/object_literal.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#line

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ObjectLiteral

Returns a new instance of ObjectLiteral.



5
6
7
8
# File 'lib/twostroke/ast/object_literal.rb', line 5

def initialize(*args)
  @items = []
  super *args
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



3
4
5
# File 'lib/twostroke/ast/object_literal.rb', line 3

def items
  @items
end

Instance Method Details

#collapseObject



10
11
12
13
# File 'lib/twostroke/ast/object_literal.rb', line 10

def collapse
  collapsed = items.map { |k,v| [k, v.collapse] }
  self.class.new items: collapsed
end

#walk(&bk) ⇒ Object



15
16
17
18
19
# File 'lib/twostroke/ast/object_literal.rb', line 15

def walk(&bk)
  if yield self
    items.each { |i| i[1].walk &bk }
  end
end