Method: Pathname#read_yaml

Defined in:
lib/pleasant_path/yaml/pathname.rb

#read_yamlnil, ...

Reads the file indicated by the Pathname, and parses the contents as YAML. The returned result will be composed of only basic data types, e.g. nil, true, false, Numeric, String, Array, and Hash.

Examples:

File.write("file.yaml", "key: value")

Pathname.new("file.yaml").read_yaml  # == { "key" => "value" }

Returns:

  • (nil, true, false, Numeric, String, Array, Hash)


16
17
18
# File 'lib/pleasant_path/yaml/pathname.rb', line 16

def read_yaml
  self.open("r"){|f| YAML.safe_load(f, filename: self) }
end