title: Can a Ruby method yield as an iterator or return an array depending on context?
body: <p>I have an arbitrary method in Ruby that yields multiple values so it can be handed to a block:</p>
  
  <pre><code>def arbitrary
    yield 1
    yield 2
    yield 3
    yield 4
  end
  
  arbitrary { |x| puts x }
  </code></pre>
  
  <p>I'd like to modify this method so that, if there is no block, it just returns the values as an array. So this construct would work as well:</p>
  
  <pre><code>myarray = arbitrary
  p a -----&gt; [1, 2, 3, 4, 5]
  </code></pre>
  
  <p>Is this possible in Ruby?</p>