Class: Twostroke::AST::Function

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Function

Returns a new instance of Function.



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

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

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



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

def arguments
  @arguments
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#statementsObject

Returns the value of attribute statements.



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

def statements
  @statements
end

Instance Method Details

#collapseObject



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

def collapse
  self.class.new name: name, arguments: arguments, statements: statements.reject(&:nil?).map(&:collapse)
end

#walk(&bk) ⇒ Object



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

def walk(&bk)
  if yield self
    statements.each { |s| s.walk &bk }
  end
end