title: Ternary operator with nil. How to use in Ruby
body: <p>I have return a ternary operator to retrieve and index as follows</p>
  
  <pre><code>val = (
    (@str_value.index("APPLE")).nil ? (
      (@str_value.index("DIAMOND")).nil ? @str_value.index("GARLIC") : str_value.index("DIAMOND")
    ) : @str_value.index("APPLE")
  )
  </code></pre>
  
  <p>But when I run this it gives me an error.</p>
  
  <pre><code>undefined method `nil' for nil:NilClass
  </code></pre>
  
  <p>I'm new to Ruby. What could possibly go wrong?</p>