summaryrefslogtreecommitdiff
path: root/lib/psych.rb
diff options
context:
space:
mode:
authorMarcus Stollsteimer <sto.mar@web.de>2017-12-02 14:32:29 +0100
committerMarcus Stollsteimer <sto.mar@web.de>2017-12-02 14:32:29 +0100
commit5db58be1bfa1393dbf087d972465b61b3d6baa31 (patch)
tree3d5604e918b6fb355c124af11a8e81e2dc57ce67 /lib/psych.rb
parentb620653700272dd71c22786f5042cd83bcfcfbc2 (diff)
downloadpsych-5db58be1bfa1393dbf087d972465b61b3d6baa31.tar.gz
Convert fallback option to a keyword argument
Converting the optional fallback argument to a keyword argument fixes a problem that is caused by mixing optional arguments and optional keyword arguments. Without this change, a hash as fallback value is not handled correctly: in Psych.load("", nil, {}) the hash is not interpreted as the fallback value, and the default value for the fallback argument is used instead.
Diffstat (limited to 'lib/psych.rb')
-rw-r--r--lib/psych.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/psych.rb b/lib/psych.rb
index 0f14fe4..03bb4a8 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -259,8 +259,8 @@ module Psych
# 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)
+ def self.load yaml, filename = nil, fallback: false, symbolize_names: false
+ result = parse(yaml, filename, fallback: fallback)
result = result.to_ruby if result
symbolize_names!(result) if symbolize_names
result
@@ -336,7 +336,7 @@ module Psych
# end
#
# See Psych::Nodes for more information about YAML AST.
- def self.parse yaml, filename = nil, fallback = false
+ def self.parse yaml, filename = nil, fallback: false
parse_stream(yaml, filename) do |node|
return node
end
@@ -483,9 +483,9 @@ module Psych
# Load the document contained in +filename+. Returns the yaml contained in
# +filename+ as a Ruby object, or if the file is empty, it returns
# the specified default return value, which defaults to an empty Hash
- def self.load_file filename, fallback = false
+ def self.load_file filename, fallback: false
File.open(filename, 'r:bom|utf-8') { |f|
- self.load f, filename, FALLBACK.new(fallback)
+ self.load f, filename, fallback: FALLBACK.new(fallback)
}
end