Pregunta

In Middleman, how can I know if a local variable exists? Local as a yaml variable. (Follow this link to know more)

For instance I can have:

row:
  first:>
    {some text}
  second:>
    {some text}

normally I would access it by data.file_name.row.first but what if I want to know if it exists?

data.file_name.row.first.nil? gives an error if does not exist...

¿Fue útil?

Solución

What error does it give? If you're getting a NoMethodError, try this:

data.file_name.try(:row).try(:first).nil?
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top