to_yaml_style

P

Pito Salas

I wanted an array:

big_array = [[1,2], [1,2], [1,2], [1,2]]


To convert into more readable yaml. (Yeah I know, YAML is for computers
to read and write but sometimes I want to eyeball it)

The default yaml I get is:

---
- - 1
- 2
- - 1
- 2
- - 1
- 2
- - 1
- 2

How ugly. I know that this is valid Yaml too:

--- [[1, 2], [1, 2], [1, 2], [1, 2]]

Sweet. I did it like this:

big_array = [[1,2], [1,2], [1,2], [1,2]]
def big_array.to_yaml_style; :inline; end
puts big_array.to_yaml

What? to_yaml_style? I found that lying around some list but can't find
any doc on it and couldn't even find it in the code. I know it must be
hiding.

Anyone know what other options there are for to_yaml_style? Because I
have some other needs that might already be built in.

Thanks much!

Pito
 

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

No members online now.

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top