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...

有帮助吗?

解决方案

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

data.file_name.try(:row).try(:first).nil?
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top