Eno::Section » #list

list(name) → array
list(name, options) → array
list(name, loader_proc, options) → array
list(name, options) { |name, value| loader_block } → array

Retrieve the items of a list, optionally supplying a loader block or Proc and options.

- pink
- peach

rubydocument = Eno.parse(input)

document.list('colors')  #=> [ 'pink', 'peach' ]
document.list('sounds')  #=> []

document.list('textures')                         # raises an error
document.list('textures', enforce_values: false)  #=> [ nil ]

document.list('sounds', required: true)         # raises an error
document.list('sounds', enforce_element: true)  # raises an error

document.list('colors') { |name, value| value.upcase }  #=> [ 'PINK', 'PEACH' ]

document.list('colors') do |name, value|
  raise 'Peach may not be on the list!' if value == 'peach'  # raises an error
  return "I like #{value}"

document.list('colors', with_elements: true)
  #=> [[ #<Eno::Field value="pink">, 'pink' ],
  #    [ #<Eno::Field value="peach">, 'peach' ]]
document.list('colors', min_count: 3)  # raises an error



The name of the list to return as a string.

loader_block or loader_proc

A block or Proc returning the transformed/validated value or raising anerror. (The block or Proc is applied to each list item on its own, itsargument signature is dynamic, you can either use |value| or |name, value|)



Whether the list must be present in the document (defaults to false)


Whether empty list items (- in the document, mapping to nil) are disallowed (defaults to true)


Validate that there are exactly n items in the list (takes a number, defaults to nil)


Validate that there are at least n items in the list (takes a number, defaults to nil)


Validate that there are at most n items in the list (takes a number, defaults to nil)


Alias for enforce_element (this exists on many methods and depending on context refers to either element or value)


Whether to return an array of arrays of the form [element, value] instead of just the values (defaults to false)

Return value

The (optionally transformed/validated) values of the items of this list as an array.With with_elements set to true it returns an array of arrays of the form [element, value] instead.