문제

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