title: how to if-else in one line in ruby?
body: <p>I want to use if-else condition in one line. I have used the ternary operator, but doesn't seem to work. Any clues?</p>
  
  <pre><code>class Array
   def painful_injection
  
     each do |item|
       sum = yield (defined?(sum).nil?) ? 0 : sum, item #pass the arguments to the block
  
     end
     sum
   end
  end
  puts [1, 2, 3, 4].painful_injection {|sum, nxt_item| sum + nxt_item}
  </code></pre>
  
  <p>This gives me an error:</p>
  
  <pre><code>Error :undefined method `+' for false:FalseClass
  </code></pre>