YAML Configuration
Load and dump YAML.
What Is YAML?
YAML (YAML Ain't Markup Language) is a human-friendly data format widely used for configuration. Ruby reads it via the yaml library (built on Psych).
require 'yaml'
text = "name: Ruby\nyear: 1995"
p YAML.load(text)Loading YAML
YAML.load parses a YAML string into Ruby objects. Mappings become Hashes, sequences become Arrays.
require 'yaml'
cfg = YAML.load("port: 8081\ndebug: true")
puts(cfg['port'])
puts(cfg['debug'])All lessons in this course
- Reading and Writing JSON
- Working with CSV
- YAML Configuration
- Choosing a Format