summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-01 01:52:26 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-01 01:52:26 +0000
commit44320c5b8d780a1572206735a88212faf9428f11 (patch)
tree33badfda3fb40eae5ce52c0e4882ae887f3df3cd /ext/psych/lib/psych.rb
parentb4070513dde45474486955fbe1a3f3e5d787a342 (diff)
Merge psych-3.0.0.
See NEWS file for this update details. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych.rb')
-rw-r--r--ext/psych/lib/psych.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index dfb6c1b00e..0f14fe445c 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -252,6 +252,13 @@ module Psych
# ex.file # => 'file.txt'
# ex.message # => "(file.txt): found character that cannot start any token"
# end
+ #
+ # When the optional +symbolize_names+ keyword argument is set to a
+ # true value, returns symbols for keys in Hash objects (default: strings).
+ #
+ # Psych.load("---\n foo: bar") # => {"foo"=>"bar"}
+ # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
+ #
def self.load yaml, filename = nil, fallback = false, symbolize_names: false
result = parse(yaml, filename, fallback)
result = result.to_ruby if result
@@ -293,7 +300,7 @@ module Psych
#
# A Psych::BadAlias exception will be raised if the yaml contains aliases
# but the +aliases+ parameter is set to false.
- def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil
+ def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil, symbolize_names: false
result = parse(yaml, filename)
return unless result
@@ -305,7 +312,9 @@ module Psych
else
visitor = Visitors::NoAliasRuby.new scanner, class_loader
end
- visitor.accept result
+ result = visitor.accept result
+ symbolize_names!(result) if symbolize_names
+ result
end
###