Skip to content
On this page

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class · Ruby 3.4

Prism::LocalVariableWriteNode

< Prism::Node 15 instance methods 2 class methods

Represents writing to a local variable.

foo = 1
^^^^^^^

Class methods 2

Instance methods 15

Attributes
Read

The number of semantic scopes we have to traverse to find the declaration of this variable.

Example
foo = 1         # depth 0

tap { foo = 1 } # depth 1

The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](github.com/ruby/prism/blob/main/docs/local_variable_depth.md).

Read

The name of the local variable, which is an [identifier](github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).

Example
foo = :bar # name `:foo`

abc = 123  # name `:abc`
Read

The value to write to the local variable. It can be any [non-void expression](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).

foo = :bar
      ^^^^

abc = 1234
      ^^^^

Note that since the name of a local variable is known before the value is parsed, it is valid for a local variable to appear within the value of its own write.

Example
foo = foo