diff options
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 1 | ||||
-rw-r--r-- | lib/psych/visitors/yast_builder.rb | 6 | ||||
-rw-r--r-- | test/visitors/test_yast_builder.rb | 5 |
3 files changed, 11 insertions, 1 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index ee603ff..e585a01 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -15,6 +15,7 @@ module Psych unless o.quoted return nil if o.value =~ /^(null|~)$/i or o.value.empty? + return o.value.sub(/^:/,'').to_sym if o.value =~ /^:/ end o.value diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb index 52eae59..c3bd55d 100644 --- a/lib/psych/visitors/yast_builder.rb +++ b/lib/psych/visitors/yast_builder.rb @@ -21,7 +21,7 @@ module Psych end def visit_String o - quote = !!(o =~ /^(null|~)$/i or o.empty?) + quote = !!(o =~ /^(null|~)$/i or o =~ /^:/ or o.empty?) scalar = Nodes::Scalar.new(o, nil, nil, !quote, quote) @stack.last.children << scalar @@ -52,6 +52,10 @@ module Psych append Nodes::Scalar.new('', nil, 'tag:yaml.org,2002:null', false) end + def visit_Symbol o + append Nodes::Scalar.new ":#{o}" + end + private def append o @stack.last.children << o diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb index bcf0cd2..91eef1c 100644 --- a/test/visitors/test_yast_builder.rb +++ b/test/visitors/test_yast_builder.rb @@ -10,6 +10,7 @@ module Psych def test_scalar assert_round_trip 'foo' + assert_round_trip ':foo' assert_round_trip '' end @@ -36,6 +37,10 @@ module Psych assert_round_trip(%w{ a b }) end + def test_symbol + assert_round_trip :foo + end + # http://yaml.org/type/null.html def test_nil assert_round_trip nil |