End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Psych.unsafe_load
# File tmp/rubies/ruby-3.0.5/ext/psych/lib/psych.rb, line 274
def self.unsafe_load yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: false, symbolize_names: false, freeze: false
if legacy_filename != NOT_GIVEN
warn_with_uplevel 'Passing filename with the 2nd argument of Psych.load is deprecated. Use keyword argument like Psych.load(yaml, filename: ...) instead.', uplevel: 1 if $VERBOSE
filename = legacy_filename
end
result = parse(yaml, filename: filename)
return fallback unless result
result.to_ruby(symbolize_names: symbolize_names, freeze: freeze)
end
Load yaml in to a Ruby data structure. If multiple documents are provided, the object contained in the first document will be returned. filename will be used in the exception message if any exception is raised while parsing. If yaml is empty, it returns the specified fallback return value, which defaults to false.
Raises a Psych::SyntaxError when a YAML syntax error is detected.
Example:
Psych.load("--- a") # => 'a' Psych.load("---\n - a\n - b") # => ['a', 'b'] begin Psych.load("--- `", filename: "file.txt") rescue Psych::SyntaxError => ex 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"}
Raises a TypeError when yaml parameter is NilClass
NOTE: This method *should not* be used to parse untrusted documents, such as YAML documents that are supplied via user input. Instead, please use the safe_load method.