API for dumping file #129

Closed
sheerun opened this Issue Feb 27, 2013 · 4 comments

Projects

None yet

3 participants

@sheerun

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

@zzak
Ruby Programming Language member

Do you mean in conjuncture with ::parse_file?

@zzak
Ruby Programming Language member

What is the long way of doing this now?

Psych.parse_file('path/to/yml').to_ruby?

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

possibly with some utf-8 flags

@tenderlove
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                        
0000012
@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