Last active
August 29, 2015 14:04
-
-
Save bitops/229040ee2d1c27b356c9 to your computer and use it in GitHub Desktop.
A yaml parser that behaves as you would expect.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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