Is Ruby's parse tree accessible (prior to evaluation)

Is there any hook to get at the parsed-tree equivalent of Ruby
expressions (and statements) before these are evaluated?

Thanks

Not directly but there is bruby (not sure name is correct) by the exerb
author and also my Ruth extension. Ruth has been heavily updated and I’m
about to release a new version shortly. It can dump the internal trees and
also transform them to something more like an AST. It can give you the
parse tree for already “compiled” code or be called on a string. I’ve done
some work on going the other way, ie from the Ruby representation of the
parse tree back to Ruby’s internal representation (since that would allow
some really cool/bizarre stuff) but it got messy. I hope to revisit that
some day.

There is also NodeDump by Dave Thomas and ii by Guy Decoux. I don’t think
any of them can give you a Ruby representation. They can dump the tree to
text though.

Regards,

Robert Feldt

···

On Tue, 10 Jun 2003, you CAN teach an old dog … wrote:

Is there any hook to get at the parsed-tree equivalent of Ruby
expressions (and statements) before these are evaluated?

In article a6e48b6b.0306091626.41f55a3a@posting.google.com,

···

you CAN teach an old dog … itsme213@hotmail.com wrote:

Is there any hook to get at the parsed-tree equivalent of Ruby
expressions (and statements) before these are evaluated?

Thanks

Not officially. That would be very nice. But you can take a look at Dave
Thomas’ nodedump program at:

http://pragmaticprogrammer.com/ruby/downloads/nodeDump.html

…there’s also a link to a similar program called ii on the same page.

Phil

Is there a ruby way to enforce specific capitalization style?

i.e.
change “JOHN DOE” to “John Doe”

In C++ I search for a space then captalize the next letter and capitalize the first letter of the string.

Thanks!

Here is a thought:

String#capitalize capitalized the first letter. So it doesn’t do quite
what you want:

“john”.capitalize #=> “John”
“john doe”.capitalize #=> “John doe”

So I would split, then capitalize, then join:

“john doe jr”.split.map{|e| e.capitalize}.join(" ") #=> “John Doe Jr”

HTH,
Daniel.

···

On Wed, Jun 11, 2003 at 08:34:16AM +0900, Steven Ketcham wrote:

Is there a ruby way to enforce specific capitalization style?

i.e.
change “JOHN DOE” to “John Doe”

In C++ I search for a space then captalize the next letter and
capitalize the first letter of the string.

Thanks!


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

I’ve put a version of capitalize that takes punctuation into account up
at http://www.rubygarden.org/ruby?StringCapitalize . You might also find
the following interesting: http://zem.novylen.net/ruby/titlecase.rb -
titlecase should cover proper names in most cases (no pun intended).

martin

···

Steven Ketcham stedak@charter.net wrote:

Is there a ruby way to enforce specific capitalization style?

i.e.
change “JOHN DOE” to “John Doe”

So I would split, then capitalize, then join:

“john doe jr”.split.map{|e| e.capitalize}.join(" ") #=> “John Doe Jr”

To preserve whitespaces, try:

“JOHN doe jr”.gsub(/\w+/) { |m| m.capitalize } #=> “John Doe Jr”

Gennady.

···

HTH,
Daniel.

On Wed, Jun 11, 2003 at 08:34:16AM +0900, Steven Ketcham wrote:

Is there a ruby way to enforce specific capitalization style?

i.e.
change “JOHN DOE” to “John Doe”

In C++ I search for a space then captalize the next letter and
capitalize the first letter of the string.

Thanks!


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (SunOS)

iD8DBQE+5mwInxE8DWHf+OcRAiFsAKDeqdqV2VyLDmZbRvdxYYfAu/ezFwCeNqNw
9vmjrNyWW3mcMKGZ7pEo7kY=
=ibnz
-----END PGP SIGNATURE-----