to_yaml is a Ruby method that returns a YAML markup string representation of the object.
Questions tagged [to-yaml]
12 questions
14
votes
2 answers
Rails console 'y' helper returns NameError rather than yaml-formatting output
I'm trying to use y object in Rails 3.2.6/Ruby 1.9.3 console to get nicely formatted yaml output for an ActiveRecord object, but for some reason it isn't working for me. I've used it in the past, but somewhere along the way it broke. I get the…

swrobel
- 4,053
- 2
- 33
- 42
6
votes
1 answer
How to get the formatting options for the to_yaml method working on ruby 1.9.1?
According to the YAML documentation it's possible to pass a hash of options to the .to_yaml method.
Currently when I pass the options as suggested by the documentation it's not working, the hash is being ignored.
irb(main):001:0> require 'yaml'
=>…

jpemberthy
- 7,473
- 8
- 44
- 52
5
votes
3 answers
Can Ruby's YAML module be used to embed comments?
The to_yaml method produces nice YAML output, but I would like to include comment lines before some of the elements. Is there a way to do so?
For example, I would like to produce:
# hostname or IP address of client
client: host4.example.com
#…

sutch
- 1,225
- 1
- 13
- 28
4
votes
1 answer
Depth limited pp or to_yaml in ruby
Can I limit the recursion depth of PP.pp or to_yaml in Ruby?
If not is there another function I can use?

rhlee
- 3,857
- 5
- 33
- 38
3
votes
2 answers
Helm `toYaml` does not retain the order
Trying to get log4j2 section form values.yml using toYaml but it does not retain the order.
log4j2.yml: |-
{{ toYaml .Values.log4j2 | indent 4 }}
output-
log4j2:
Configuration:
Appenders:
Console:
Filters:
…

Sivangi Singh
- 31
- 3
3
votes
1 answer
In ruby-on-rails, how to convert the '\X93' like string format to its original look?
s = "你好"
s.encoding # => #
yaml = s.to_yaml # => "--- \"\\xE4\\xBD\\xA0\\xE5\\xA5\\xBD\"\n"
yaml.encoding # => #
yaml.force_encoding 'utf-8' # => "---…

Croplio
- 3,433
- 6
- 31
- 37
3
votes
2 answers
How to use to_yaml method in Rails, and remove '---'
I'm trying to generate a hash in yaml format, but by default, this method always adds --- in front of the object.
> h = {key1: 'v1', key2: 'v2'}
=> {:key1=>"v1", :key2=>"v2"}
> h.deep_stringify_keys.to_yaml
=> "---\n:key1: v1\n:key2: v2\n"

rplaurindo
- 1,277
- 14
- 23
3
votes
4 answers
Ruby to_yaml utf8 string
How can I make ruby to_yaml method to store utf8 strings with original signs but not escape sequence?

Bogdan Gusiev
- 8,027
- 16
- 61
- 81
2
votes
1 answer
can't dump anonymous class Class
I get a strange issue on the server as below
/!\ FAILSAFE /!\ Wed Apr 25 19:35:13 +0000 2012
Status: 500 Internal Server Error
can't dump anonymous class Class
Please Have a look on the backtrace of issue Click Here
FYI, Server has ruby 1.8.7 and…

Chirag Shah
- 509
- 1
- 10
- 25
1
vote
1 answer
How do I parse a field in a YAML file into three more fields in the same file?
I have a YAML file containing:
cat:
name: Cat
description: catlike reflexes
dog:
name: Dog
description: doggy breath
I want to parse it and break the description into key1 and key2 like so:
cat:
name: Cat
description: catlike reflexes
…

Tom Prats
- 7,364
- 9
- 47
- 77
0
votes
1 answer
How to style to_yaml correctly
I want to store some configuration information about a few apps so I can make an 'app drawer'. I store the info in an array that looks like this -
[["page_view", {"path"=>"somepath/asdf/asdf", "name"=>"Page View"}], ["outage_impact",…

Josh
- 5,631
- 1
- 28
- 54
0
votes
3 answers
checking the form data received in ruby on rails controller
I want to check the form data received from the form in ruby on rails controller.
I tried this but nothing is shown:
@user.to_yaml
where @user is the form name(<%=form_for @user )

Sachin Prasad
- 5,365
- 12
- 54
- 101