diff options
author | SHIBATA Hiroshi <hsbt@ruby-lang.org> | 2017-12-19 17:34:52 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-19 17:34:52 +0900 |
commit | e90cceab21cccaa41ee742773ea18af5a11cc146 (patch) | |
tree | 5ca81162fa81e1ca81c1cae98d57acfa0adf08e1 | |
parent | 6333cf8cc365b644fbffd8b122f2e720f5654e77 (diff) | |
parent | 5db58be1bfa1393dbf087d972465b61b3d6baa31 (diff) | |
download | psych-e90cceab21cccaa41ee742773ea18af5a11cc146.tar.gz |
Merge pull request #342 from stomar/fallback-keyword
Convert fallback option to a keyword argument
-rw-r--r-- | lib/psych.rb | 10 | ||||
-rw-r--r-- | test/psych/test_psych.rb | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index aea3565..a4d5a96 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 @@ -346,7 +346,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 @@ -493,9 +493,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 diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index 82906f0..2812fd1 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -146,7 +146,7 @@ class TestPsych < Psych::TestCase def test_load_file_with_fallback Tempfile.create(['empty', 'yml']) {|t| - assert_equal Hash.new, Psych.load_file(t.path, Hash.new) + assert_equal Hash.new, Psych.load_file(t.path, fallback: Hash.new) } end |