From: Brad Phelan Date: 2007-05-30T02:55:11+09:00 Subject: Re: How to adopt "Python Style" indentation for Ruby Giles Bowkett wrote: > Obviously based on the earlier thread. I think this is actually an > utterly terrible idea. Haven't you heard that song by Loverboy? "Pig > and elephant DNA just don't mix"? But I think the **implementation** > would be fascinating. > > What would it take to write a Ruby pre-processor which parsed Ruby > written in a Pythonic style and turned it into actual valid Ruby? Or > even a Ruby library like Xavier's Perl example, which allows you to > code Ruby as if it were Python after just requiring the library? The > original post's main argument was that indentation is a stable, > consistent shorthand for Ruby's end statements. If all you're looking > to do is use tabs as syntactic sugar, then it should be pretty easy to > just write something which knows how to translate a sequence of tabs > in and tabs out into a series of end statements at the end. > > Is this only doable in Perl, because Perl has source filtering? Would > you have to encase the Pythonic "Ruby" in a string and then run that > string through a processor after the fact, or could it "just work" > without any obvious prep on the user's part? If you did it as a > string, it should be as easy as counting tabs. But source filtering, > that sounds like the better way. > Another version of pyrb.rb has been written that allows proper multilevel dedenting and removes the requirement for a separate .pyrb file You can now do in test.rb ##################################### require 'pyrb.rb' __END__ def foo: [1,2,3,4].each do |i|: puts i [1,2,3,4].each do |j|: puts i if i == 2 : puts "foo" else: puts "bar" foo ##################################### http://xtargets.com/snippets/posts/show/68 Disclaimer : The above library in no way whatsoever should be taken as a suggestion that the author thinks Python is better than Ruby or vice versa. All suggestions to that effect are purely fictional and the author is in no way responsible for flame wars that may ensue from use or misuse of the library. The author wrote the library because it could be done and for no other reason. -- Brad Phelan http://xtargets.com