summaryrefslogtreecommitdiff
path: root/lib/psych/visitors/to_ruby.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-07-24 15:20:40 -0400
committerJean Boussier <jean.boussier@gmail.com>2019-11-28 09:33:30 +0000
commit3e472ab2d71c45d6d68b4c87f4b9a9484bf66c06 (patch)
treee7527f1b97ec90453b4de53ba0e41d196183e503 /lib/psych/visitors/to_ruby.rb
parent2a06e8360e28e99c26f1645f476b76677ecebd55 (diff)
downloadpsych-3e472ab2d71c45d6d68b4c87f4b9a9484bf66c06.zip
Refactor `symbolize_names`
Diffstat (limited to 'lib/psych/visitors/to_ruby.rb')
-rw-r--r--lib/psych/visitors/to_ruby.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index b72fb4a..3021aa7 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -12,20 +12,21 @@ module Psych
###
# This class walks a YAML AST, converting each node to Ruby
class ToRuby < Psych::Visitors::Visitor
- def self.create
+ def self.create(symbolize_names: false)
class_loader = ClassLoader.new
scanner = ScalarScanner.new class_loader
- new(scanner, class_loader)
+ new(scanner, class_loader, symbolize_names: symbolize_names)
end
attr_reader :class_loader
- def initialize ss, class_loader
+ def initialize ss, class_loader, symbolize_names: false
super()
@st = {}
@ss = ss
@domain_types = Psych.domain_types
@class_loader = class_loader
+ @symbolize_names = symbolize_names
end
def accept target
@@ -336,7 +337,12 @@ module Psych
SHOVEL = '<<'
def revive_hash hash, o
o.children.each_slice(2) { |k,v|
- key = deduplicate(accept(k))
+ key = accept(k)
+ if @symbolize_names
+ key = key.to_sym
+ else
+ key = deduplicate(key)
+ end
val = accept(v)
if key == SHOVEL && k.tag != "tag:yaml.org,2002:str"