API for dumping file #129

sheerun opened this Issue Feb 27, 2013 · 4 comments


None yet

3 participants


There is Psych.parse_file. Any reason why Psych.dump_file has not been implemented?

Ruby Programming Language member

Do you mean in conjuncture with ::parse_file?

Ruby Programming Language member

What is the long way of doing this now?


File.open('path/to/yml', 'w') do |file|
  file.write(Psych.dump([1, 2, 3]))

possibly with some utf-8 flags

Ruby Programming Language member

It's mainly for backwards compatibility. I'd like to avoid explicitly teaching Psych what a file is. Like Marshal, you can give Psych.dump an IO, and it will write to the IO:

$ ruby -rpsych -e'Psych.dump([1,2,3], File.open("x", "w"))'
$ cat x
- 1
- 2
- 3
$ ruby -e'Marshal.dump([1,2,3], File.open("y", "w"))'
$ od -c y
0000000  004  \b   [  \b   i 006   i  \a   i  \b                        
@tenderlove tenderlove closed this Apr 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment