End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
RubyVM::AbstractSyntaxTree::Node#source
node.source → string
ast.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/ast.rb, line 264
def source
lines = script_lines
if lines
lines = lines[first_lineno - 1 .. last_lineno - 1]
lines[-1] = lines[-1][0...last_column]
lines[0] = lines[0][first_column..-1]
lines.join
else
nil
end
end
Returns the code fragment that corresponds to this AST.
Note that this is an API for ruby internal use, debugging, and research. Do not use this for any other purpose. The compatibility is not guaranteed.
Also note that this API may return an incomplete code fragment that does not parse; for example, a here document following an expression may be dropped.