whitequark / ast

A library for working with Abstract Syntax Trees.
MIT License
195 stars 25 forks source link

#inspect should return valid Ruby code #1

Closed yorickpeterse closed 10 years ago

yorickpeterse commented 11 years ago

Instead of this:

(str "hello")

The method AST::Node#inspect should return the following instead:

s(:str, "hello")

This makes it possible to directly copy-paste the output and run it (assuming the #s() method is defined).

whitequark commented 10 years ago

Hm, not sure how this slipped my attention for a year. I think it such a feature could be provided by a #to_ruby method, which should also print the code for metadata.

whitequark commented 10 years ago

@YorickPeterse still interested?

yorickpeterse commented 10 years ago

Not in particular. Thinking about it this feature wouldn't address the problem of nodes having extra metadata (that isn't specified in the child nodes). Thus, even if the output were valid Ruby code it wouldn't have all the information that might've initially been available.