method
load
v2_6_3 -
Show latest stable
-
0 notes -
Class: Psych
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125 (0)
- 1_9_3_392 (38)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (31)
- 2_6_3 (17)
- What's this?
load(yaml, legacy_filename = NOT_GIVEN, filename: nil, fallback: false, symbolize_names: false)
public
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"}