Close

gem – yaml

Yaml actually comes as part of the ruby core, therefore there is no ruby gem for it.

Announcement

You can find all my latest posts on medium.

Lets say you have the following yaml file:

$ cat /etc/credentials.yaml
---
:foreman:
  :username: 'codingbee'
  :password: 'liverpool'

now you want use these content, then you do:

cat yamldemo.rb
require 'yaml'

credentials = YAML.load_file("/etc/credentials.yaml")
@username = credentials[:foreman][:username]
@password = credentials[:foreman][:password]

puts @username
puts @password


Which leads to:

$ ruby yamldemo.rb
codingbee
liverpool