Ruby Beautifier

Hi,

Is there a Ruby beautifier out there that can do more than just
indenting?

Some things I'd like to do are

* change a single line with semi-colon separated statements into
multiple lines with no semi-colons.

* change multi line blocks with {...} to multi line blocks with
do...end

What other features would be good?

Thanks,
Peter

store.rb - http://trac.vaillant.ca/store.rb

petermichaux@yahoo.com wrote:

Hi,

Is there a Ruby beautifier out there that can do more than just
indenting?

Some things I'd like to do are

* change a single line with semi-colon separated statements into
multiple lines with no semi-colons.

* change multi line blocks with {...} to multi line blocks with
do...end

What other features would be good?

The following would be good if the programmer could set the values. Here are some examples of little things...

Change "meth(a)" to "meth( a )"

Change "meth(a,b,c,d)" to "meth( a, b, c, d )"

Put consistency spacing between the end of a \w and the beginning of {
Example:
    "arr.each{ |i| .. }" to "arr.each { |i| ... }"

Move multiline conditional statements that only have 1 line of code to 1 line. Example:
     if condition
        my_obj.do_something_here
     end
to:
     my_obj.do_something_here if condition
Of source maximum line length may want to be considered.

Change calls like:
   method :key1=>val, :key2=>val2
to:
   method( :key1=>val, :key2=>val2 )

Also change things like:
   method :key1 => val,
     :key2 => val,
     :key3 =>val
to:
    method( :key1 => val,
     :key2 => val,
     :key3 =>val )

Allow user to specify number of spaces if any between hash key/vals. So:
    h = { :key=>:val }
to perhaps:
    h = { :key => :val }
or vise versa.

...

Zach

ruby2ruby.rb in ZenHacks can do this at the cost of your comments (and code in toplevel and class scope).

ยทยทยท

On Oct 31, 2005, at 9:17 AM, petermichaux@yahoo.com wrote:

Hi,

Is there a Ruby beautifier out there that can do more than just
indenting?

Some things I'd like to do are

* change a single line with semi-colon separated statements into
multiple lines with no semi-colons.

* change multi line blocks with {...} to multi line blocks with
do...end

What other features would be good?

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

How are code beautifiers usually written? Seems as complicated as a
code parser.

Some things I'd like to do are

* change a single line with semi-colon separated statements into
multiple lines with no semi-colons.

* change multi line blocks with {...} to multi line blocks with
do...end

What other features would be good?

The following would be good if the programmer could set the values. Here
are some examples of little things...

Beauty is in the eye of the beholder.
And I behold things differently...

Change "meth(a)" to "meth( a )"

*yuck* (why do you need braces *and* spaces to put meth and a clearly on
the screen?)

and why not
  "meth a"

Change "meth(a,b,c,d)" to "meth( a, b, c, d )"

Put consistency spacing between the end of a \w and the beginning of {
Example:
    "arr.each{ |i| .. }" to "arr.each { |i| ... }"

"arr.each {|i| ... }

Move multiline conditional statements that only have 1 line of code to 1
line. Example:
     if condition
        my_obj.do_something_here
     end
to:
     my_obj.do_something_here if condition

I like
  "bla die bla if something"

Of source maximum line length may want to be considered.

Change calls like:
   method :key1=>val, :key2=>val2
to:
   method( :key1=>val, :key2=>val2 )

why? and again those *yuck* spaces within the braces

Also change things like:
   method :key1 => val,
     :key2 => val,
     :key3 =>val
to:
    method( :key1 => val,
     :key2 => val,
     :key3 =>val )

method(
  :key1 => val,
  :key2 => val
)

Allow user to specify number of spaces if any between hash key/vals. So:
    h = { :key=>:val }
to perhaps:
    h = { :key => :val }
or vise versa.

+--- Kero ------------------------- kero@chello@nl ---+

all the meaningless and empty words I spoke |
                      Promises -- The Cranberries |

+--- M38c --- http://members.chello.nl/k.vangelder ---+