TRB JOBS: Deutschsprachiger Ruby Developer in Hannover - Jaaaa!


Representable: YAML

Last updated 27 January 2017

Representable YAML

Representable also comes with a YAML representer. Like XML, the declarative API is almost identical.

Flow Style Lists

A nice feature is that #collection also accepts a :style option which helps having nicely formatted inline (or “flow”) arrays in your YAML - if you want that!

require 'representable/yaml'

class SongRepresenter < Representable::Decorator
  include Representable::YAML

  property :title
  property :id
  collection :composers, style: :flow

Public API

To render and parse, you invoke to_yaml and from_yaml.

Song =, :id, :composers)
song ="Fallout", 1, ["Stewart Copeland", "Sting"])
title: Fallout
id: 1
composers: [Stewart Copeland, Sting]