# Making all my Ruby files pretty

**URL:** <https://www.ruby-forum.com/t/making-all-my-ruby-files-pretty/132234>\
**Category:** Ruby\
**Created:** [March 18, 2008, 5:47am UTC](https://www.ruby-forum.com/t/making-all-my-ruby-files-pretty/132234 "2008-03-18T05:47:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [March 18, 2008, 5:47am UTC](https://www.ruby-forum.com/t/making-all-my-ruby-files-pretty/132234/1 "2008-03-18T05:47:26Z")

</div>

Hello!

I’m trying to make a simple Ruby code beautifier to set me at ease. I  
know there’s already rbeautify:

> **[Ruby Beautifier Script Listing](https://arachnoid.com/ruby/rbeautify.rb.html)**
>
> Ruby Source Code Beautifier.

But I need to do some more:

Like making,

# comments like these

Into,

# 

# Comments like these.

# 

E.g. making sure the first letter after "^# " (if any) is always  
uppercase and that every comment line ends with a dot.

As well as,

# comments like these.

# bla bla.

# bla blaaa.

Into,

# 

# Comments like these. Bla bla. Bla blaaa.

# 

Every comment is always joined into one line.

I’m not sure exactly what approach to take. Whether to build on  
rbeautify or not. I also need the functionality from my old shell  
script:

#!/usr/bin/env zsh

for file in $PWD/\*\*/\*(.); do

```
# Check if file is text.
#
if file -b $file | grep -q 'text'; then

    # Remove CRLF, blank lines and trailing white space.
    #
    # In FreeBSD use: sed -e
    #
    tr -d '\r' < $file | sed -E -e 'v/\S/d' -e 's/[[:space:]]+$//' >

```

$file.tmp

```
    mv -f $file.tmp $file

echo "$file"

fi

```

done

Would love to hear what you guys think.

All the best,  
Kyrre

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [March 18, 2008, 12:49pm UTC](https://www.ruby-forum.com/t/making-all-my-ruby-files-pretty/132234/2 "2008-03-18T12:49:20Z")

</div>

Kyrre Nygård wrote:

> # comments like these.
> 
> # bla bla.
> 
> # bla blaaa.

Comments…?

COMMENTS???

Look around you! Do you see any comments in these programs?

(Besides the RDoc meat…😉

–  
Phlip

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [March 18, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/making-all-my-ruby-files-pretty/132234/3 "2008-03-18T15:44:46Z")

</div>

> E.g. making sure the first letter after "^# " (if any) is always  
> uppercase and that every comment line ends with a dot.  
> […]  
> Every comment is always joined into one line.

- Get a list of files you want to “beautify” (e.g. by means of Dir.glob)
- Load the contents of these files
- Use regex to find/replace & upcase for your uppercasing needs
- Save.

Google will be a wonderful resource for all “yeah, but how?” issues you  
might run into along the way. It will be a brief, yet interesting,  
programming exercise. Gaining some regex experience never hurts 🙂

Cheers,  
Niels

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [March 18, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/making-all-my-ruby-files-pretty/132234/4 "2008-03-18T17:46:03Z")

</div>

Niels G. wrote:

> Google will be a wonderful resource for all “yeah, but how?” issues you  
> might run into along the way. It will be a brief, yet interesting,  
> programming exercise. Gaining some regex experience never hurts 🙂

Yeah! What he sed!

---

<div class="post-metadata">

**Author:** ![Kyrre\_NygSSSSrd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@Kyrre\_NygSSSSrd](https://www.ruby-forum.com/u/Kyrre_NygSSSSrd)\
**Post date:** [March 19, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/making-all-my-ruby-files-pretty/132234/5 "2008-03-19T17:33:35Z")

</div>

Thanks man 🙂

I appreciate it. I wonder why though nobody’s done this kind of thing  
before.

Where’s the love?

Kyrre

----- Original Message -----  
From: Niels G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Tuesday, March 18, 2008 10:44 pm  
Subject: [Rails] Re: Making all my Ruby files pretty  
To: removed\_email\_address@domain.invalid
