Ameba::AST::Variable
Represents the existence of the local variable. Holds the var node and variable assignments.
Constructors
Creates a new variable(in the scope).
Variable.new(node, scope)
Instance methods
assign(node, scope)
Assigns the variable (creates a new assignment). Variable may have multiple assignments.
variable = Variable.new(node, scope)
variable.assign(node1)
variable.assign(node2)
variable.assignments.size # => 2
captured_by_block?(scope = @scope)
Returns true if the current var is referenced
in the block. For example this variable is captured
by block:
a = 1
3.times { |i| a = a + i }
And this variable is not captured by block.
i = 1
3.times { |i| i + 1 }
end_location(*args, **options)
Sourceend_location(*args, **options, &)
Sourcelocation(*args, **options)
Sourcelocation(*args, **options, &)
Sourcename(*args, **options)
Sourcename(*args, **options, &)
Sourcereference(node : Crystal::Var, scope : Scope)
Creates a reference to this variable in some scope.
variable = Variable.new(node, scope)
variable.reference(var_node, some_scope)
reference(scope : Scope)
Creates a reference to this variable in some scope.
variable = Variable.new(node, scope)
variable.reference(var_node, some_scope)
referenced?
Returns true if variable has any reference.
variable = Variable.new(node, scope)
variable.reference(var_node, some_scope)
variable.referenced? # => true
target_of?(assign)
Returns true if the variable is a target (on the left) of the assignment,
false otherwise.
to_s(*args, **options)
Sourceto_s(*args, **options, &)
Sourceused_in_macro?(scope = @scope)
Returns true if current variable potentially referenced in a macro,
false if not.