5

Every to_yaml output have three leading dashes:

---
a:
  b:
    c: soemthing

How convert object to yaml without leading dashes?

rootatdarkstar
  • 1,486
  • 2
  • 15
  • 26

2 Answers2

1

Under the hood, to_yaml uses Psych to parse and emit your data.

Though there are optional parameters you can specify (listed here), none suppress the leading dashes.

The simplest approach would be to gsub away the dashes.

object.to_yaml.gsub(/^---$/, "")
j.r.clarkin
  • 516
  • 5
  • 6
0

From the YAML specification:

YAML uses three dashes (“---”) to separate directives from document content. This also serves to signal the start of a document if no directives are present.

That means: Your example starts as a valid YAML document should start. Nothing wrong with it.

spickermann
  • 100,941
  • 9
  • 101
  • 131