Skip to content

Instantly share code, notes, and snippets.

@bitops
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitops/229040ee2d1c27b356c9 to your computer and use it in GitHub Desktop.
Save bitops/229040ee2d1c27b356c9 to your computer and use it in GitHub Desktop.
A yaml parser that behaves as you would expect.
require 'yaml'
module BetterYaml
def self.write_yaml_file(file, data)
self.with_syck_engine do
File.open(File.expand_path(file), "w", :encoding => "utf-8") {|f| YAML.dump(data, f) }
end
end
def self.load_yaml_file(file)
self.with_syck_engine do
::YAML.load_file(File.expand_path(file))
end
end
def self.with_syck_engine
engine = ::YAML::ENGINE.yamler
::YAML::ENGINE.yamler = "syck"
result = yield
::YAML::ENGINE.yamler = engine
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment