Ruby Beautifier

P

petermichaux

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
 
Z

Zach Dennis

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
 
P

petermichaux

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

Eric Hodel

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?

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

Kero

Some things I'd like to do are
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 ---+
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top