[ruby-core:75843] [CommonRuby Feature#12057] Allow methods with `yield` to be called without a block

From: afrejt@...
Date: 2016-06-04 19:56:53 UTC
List: ruby-core #75843
Issue #12057 has been updated by James  Bond.


Thank you for the read. Honestly you covered the topic and broadly examined all
~~~
areas. If i was to write this i would have done a few things differently myself but you have definitely inspired me to get into the world of blogging. Thanks heaps for the post i really appreciate it. Have a good day and keep blogging
~~~ [url=http://www.galaxyessay.com/]galaxyessay.com[/url]

----------------------------------------
Feature #12057: Allow methods with `yield` to be called without a block
https://bugs.ruby-lang.org/issues/12057#change-59018

* Author: Alexey Muranov
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Trying to figure out how `yield` works in Python, i had the following idea.

Allow a method with `yield` to be called without a block.  When a method encounters `yield`, if no block is given, the method returns an `Enumerator` object.

~~~ruby
def f
  yield 'a'
  yield 'b'
end

e = f
puts e.next  # => a
puts e.next  # => b
~~~

It seems that this is what `yield` in Python does, but in Python a function with `yield` cannot take a block. Why not to have both?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next