Class: Rubinius::AST::Block

Inherits:
Node
  • Object
show all
Defined in:
lib/compiler/ast/definitions.rb

Overview

Is it weird that Block has the :arguments attribute? Yes. Is it weird that MRI parse tree puts arguments and block_arg in Block? Yes. So we make do and pull them out here rather than having something else reach inside of Block.

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk

Constructor Details

#initialize(line, array) ⇒ Block

Returns a new instance of Block.



45
46
47
48
49
50
51
52
# File 'lib/compiler/ast/definitions.rb', line 45

def initialize(line, array)
  @line = line
  @array = array

  # These are any local variable that are declared as explicit
  # locals for this scope. This is only used by the |a;b| syntax.
  @locals = nil
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



43
44
45
# File 'lib/compiler/ast/definitions.rb', line 43

def array
  @array
end

#localsObject

Returns the value of attribute locals.



43
44
45
# File 'lib/compiler/ast/definitions.rb', line 43

def locals
  @locals
end

Instance Method Details

#strip_argumentsObject



54
55
56
57
58
59
60
61
62
# File 'lib/compiler/ast/definitions.rb', line 54

def strip_arguments
  if @array.first.kind_of? FormalArguments
    node = @array.shift
    if @array.first.kind_of? BlockArgument
      node.block_arg = @array.shift
    end
    return node
  end
end

#to_sexpObject



64
65
66
# File 'lib/compiler/ast/definitions.rb', line 64

def to_sexp
  @array.inject([:block]) { |s, x| s << x.to_sexp }
end