# To\_yaml method

**URL:** <https://www.ruby-forum.com/t/to-yaml-method/91369>\
**Category:** Ruby\
**Created:** [April 7, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/to-yaml-method/91369 "2007-04-07T17:28:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@simonr](https://www.ruby-forum.com/u/simonr)\
**Post date:** [April 7, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/to-yaml-method/91369/1 "2007-04-07T17:28:51Z")

</div>

Hello,

In order to learn Ruby, I am trying to write a Getting Things Done  
manager in Ruby+YAML.

So, here is where I am : [Parked at Loopia](http://pastie.caboo.se/52303)  
Be carefull… Store#to\_yaml is realy ugly !  
So, how can I make this method prettier ?

BTW, this is probably not the only ugly method… so feel free to  
correct me, it’ll  
help me to learn the Ruby Way 🙂

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![simonr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@simonr](https://www.ruby-forum.com/u/simonr)\
**Post date:** [April 7, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/to-yaml-method/91369/2 "2007-04-07T18:00:05Z")

</div>

Check out [http://RubyMentor.rubyfoge.org](http://RubyMentor.rubyfoge.org) for exactly this kind of  
help/advice.

Aur

---

<div class="post-metadata">

**Author:** ![simonr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@simonr](https://www.ruby-forum.com/u/simonr)\
**Post date:** [April 7, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/to-yaml-method/91369/3 "2007-04-07T18:19:07Z")

</div>

Thanks. I feel a bit uncomfortable with having a mentor (I don’t know  
exactly why… maybe that’s too easy ?) but I’ll try to contact a  
mentor and see what happen 🙂  
BTW, the concept is realy interesting… IMHO having a mentor is the  
best way to learn something. AFAIK I haven’t seen project like this on  
other porgramming language communauty.

2007/4/7, SonOfLilit [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![simonr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@simonr](https://www.ruby-forum.com/u/simonr)\
**Post date:** [April 7, 2007, 6:49pm UTC](https://www.ruby-forum.com/t/to-yaml-method/91369/4 "2007-04-07T18:49:10Z")

</div>

Thank you.

Don’t be uncomfortable, the worst that could happen is nothing.

I agree that the concept is interesting and great, and I, too, think  
it’s original.

Hopefully you’ll join the rank of mentors soon 🙂

Aur

---

<div class="post-metadata">

**Author:** ![simonr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@simonr](https://www.ruby-forum.com/u/simonr)\
**Post date:** [April 7, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/to-yaml-method/91369/5 "2007-04-07T19:07:12Z")

</div>

On 4/7/07, Simon R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > So, how can I make this method prettier ?
> 
> –  
> Simon R., [http://atonie.org/sr/](http://atonie.org/sr/)

A few style notes. The multiple assignment you do “tasks, projects =  
Array.new, Array.new” is usually done on two lines, just for  
readability, and dropping some complexity. Also you can just assign  
to [], which gives you a blank array ({} for hashes).

```
@projects.each_pair { |k, v| projects << v }
@tasks.each_pair { |k, v| tasks << v }

```

Can be replaced with

```
tasks = @tasks.map {|x| x }
projects = @projects.map {|x| x }

```

With this you can also drop the array initialization. This method is  
in the Enumerable module, which Hash and Array mixin. You could even  
make it just be

```
    dump = @tasks.map {|x| x }
    dump << @projects.map {|x| x }
    return YAML.dump(dump)

```

Hope that helps you some!

---

<div class="post-metadata">

**Author:** ![simonr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@simonr](https://www.ruby-forum.com/u/simonr)\
**Post date:** [April 8, 2007, 12:55am UTC](https://www.ruby-forum.com/t/to-yaml-method/91369/6 "2007-04-08T00:55:39Z")

</div>

On Apr 7, 5:27 pm, “Simon R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> correct me, it’ll  
> help me to learn the Ruby Way 🙂
> 
> Thanks in advance,
> 
> –  
> Simon R.,[Simon Rozet](http://purl.org/net/sr/)

Hey cool! A GTD application in ruby. I’m looking forward to see this  
project on [rubyforge.org](http://rubyforge.org) 😉
