Sha256: e22a336358a659cc46ac258acf9ba4788596138e8b7cc1f7d764abaabe2a1212

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

class Pathname

  # Reads the contents of the file indicated by the Pathname, and parses
  # it as YAML.  The returned result will be a basic Ruby data
  # structure, namely, one of: +nil+, +true+, +false+, a +Numeric+, a
  # +String+, an +Array+, or a +Hash+.
  #
  # @example
  #   File.write("in.yaml", "key: value")
  #
  #   Pathname.new("in.yaml").read_yaml  # == { "key" => "value" }
  #
  # @return [nil, true, false, Numeric, String, Array, Hash]
  def read_yaml
    self.open("r"){|f| YAML.safe_load(f, [], [], false, self) }
  end

  # Reads the contents of the file indicated by the Pathname, and parses
  # it as YAML.  The parser will use type information embedded in the
  # YAML to deserialize custom types.  This is *UNSAFE* for YAML from
  # an untrusted source.  To consume untrusted YAML, use
  # {Pathname#read_yaml} instead.
  #
  # @example
  #   Point = Struct.new(:x, :y)
  #   point = Point.new(10, 20)
  #   File.write("in.yaml", point.to_yaml)
  #
  #   Pathname.new("in.yaml").load_yaml  # == Point.new(10, 20)
  #
  # @return deserialized object
  def load_yaml
    YAML.load_file(self)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pleasant_path-1.2.0 lib/pleasant_path/yaml/pathname.rb