I'm using Thor and trying to output YAML to a file. In irb I get what I expect. Plain text in YAML format. But when part of a method in Thor, its output is different...
class Foo < Thor
include Thor::Actions
desc "bar", "test"
def set
test = {"name" => "Xavier", "age" => 30}
puts test
# {"name"=>"Xavier", "age"=>30}
puts test.to_yaml
# !binary "bmFtZQ==": !binary |-
# WGF2aWVy
# !binary "YWdl": 30
File.open("data/config.yml", "w") {|f| f.write(test.to_yaml) }
end
end
Any ideas?
#encoding: UTF-8
to the top of the file seems to fix it. I don't know what's going on though - it looks like thor is changing the default encoding to ASCII-8BIT and then a change to yaml in Ruby 1.9.3 causes the output to be binary. – Septime.thor
files; it usesFile.binread
which sets the encoding to ASCII-8BIT. – Septime