Method: AST::Node#inspect

Defined in:
lib/ast/node.rb

#inspect(indent = 0) ⇒ String

Converts ‘self` to a s-expression ruby string. The code return will recreate the node, using the sexp module s()

Parameters:

  • indent (Integer) (defaults to: 0)

    Base indentation level.

Returns:

  • (String)


211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/ast/node.rb', line 211

def inspect(indent=0)
  indented = "  " * indent
  sexp = "#{indented}s(:#{@type}"

  children.each do |child|
    if child.is_a?(Node)
      sexp += ",\n#{child.inspect(indent + 1)}"
    else
      sexp += ", #{child.inspect}"
    end
  end

  sexp += ")"

  sexp
end