Created
April 1, 2009 06:25
-
-
Save l15n/88570 to your computer and use it in GitHub Desktop.
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
# Set YAML output of String values in hashes to be double quoted | |
# Only modifies hashes that are about to run to_yaml | |
require 'yaml' | |
class Hash | |
def to_yaml_with_quoted_strings(*args) | |
class << self | |
unless method_defined?(:each_with_quoted_strings) | |
def each_with_quoted_strings | |
each_with_normal_strings do |k,v| | |
if String === v && !v.frozen? | |
def v.to_yaml_style; return :quote2; end | |
end | |
yield k, v | |
end | |
end | |
alias_method :each_with_normal_strings, :each | |
alias_method :each, :each_with_quoted_strings | |
end | |
end | |
return to_yaml_with_normal_strings(*args) | |
end | |
alias_method :to_yaml_with_normal_strings, :to_yaml | |
alias_method :to_yaml, :to_yaml_with_quoted_strings | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment