Built-in YAML support
The Psych standard gem provides out-of-the-box YAML support in Ruby.
Though I'll take configuration as code (i.e. directly in Ruby) over a serialized format like JSON or YAML any day of the week, it's not always an option, and when it's not, YAML tends to be the preferable option.
require "yaml"
yaml = <<~YAML
list:
- one
- two
- three
number: 108
:symbol: :hehe_yes
# OMG a comment!
better_than_json: true
YAML
hash = YAML.load(yaml)
# => {
# "list" => ["one", "two", "three"],
# "number" => 108,
# symbol: :hehe_yes,
# "better_than_json" => true,
# }
hash["list"] << "four"
File.write("file.yaml", YAML.dump(hash))
# Writes:
# ---
# list:
# - one
# - two
# - three
# - four
# number: 108
# :symbol: :hehe_yes
# better_than_json: true
Of particular note is Ruby YAML's support for symbols via the colon prefix.
I personally feel that there is a bit of a spiritual connection between YAML and Ruby in how they appear to forgo efficiency and "computer syntax" to create something more concise and human-like. Though I'm sure the whole "meaningful whitespace" thing grinds quite a few people's gears 😅
History
Ruby first gained built-in YAML support in Ruby 1.8.0, released in 2003. The original implementation was Syck, the YAML parser and emitter written by why the lucky stiff.
Psych, the libyaml-backed parser and emitter used today, was imported into Ruby in 2010 and shipped with Ruby 1.9.2, released in August that year. Ruby 1.9.3, released in October 2011, made Psych the default YAML engine while still allowing users to opt back into Syck.
Ruby 2.0, released in February 2013, removed Syck and made YAML depend fully on Psych and libyaml. For a while Ruby bundled libyaml as a fallback, but Ruby 3.2 stopped bundling those sources, so modern builds expect libyaml to be available from the system or build environment.
The wrapper around require "yaml" has remained intentionally stable through all of this. Internally it has moved from Syck to Psych and from bundled stdlib file to default gem, but the user-facing API has stayed compatible.