From: "alexeymuranov (Alexey Muranov)" Date: 2012-08-15T06:02:29+09:00 Subject: [ruby-core:47193] [ruby-trunk - Feature #6868] Make `do` in block syntax optional when the block is the last argument of a method and is not an optional argument Issue #6868 has been updated by alexeymuranov (Alexey Muranov). drbrain (Eric Hodel) wrote: > =begin > What would this code do: > > def method n > n = n.times > p n > n > end > > Currently it prints (({#})) and returns an Enumerator. Would it instead raise SyntaxError for an unexpected end? > > =end You mean, what should `method(3)` output? This was not considered in my proposal, i think it should be the same. In fact, i understand that there are issues with making `def` a method, i was only proposing to make blocks look more like class and method definitions in certain circumstances. I do not remember if there are Ruby core methods that require a block, all that come to my mind have an optional block parameter. So here is a made-up example of the use of the proposed syntax: def do_three_times(&block) 3.times(&block) end do_three_times puts "Hi" end The interpreter would need to look up the method definition for `do_three_times` before parsing the parameters (i think this is different from the current behavior), see that there is a required block parameter at the end, and so to expect either `do` or just new line to start the block after `do_three_times`. ---------------------------------------- Feature #6868: Make `do` in block syntax optional when the block is the last argument of a method and is not an optional argument https://bugs.ruby-lang.org/issues/6868#change-28872 Author: alexeymuranov (Alexey Muranov) Status: Feedback Priority: Normal Assignee: Category: core Target version: 3.0 =begin I propose to make the use of "(({do}))" in block syntax optional if the block is the last argument of a method and if it is a required argument, at least if the block does not take parameters. (I think this would be in line with how for example the last hash argument is treated.) I also think that this syntactic change may allow in future versions of Ruby to make (({def})), (({class})), (({module})) methods instead of keywords. Something like: 3.time puts "Hi!" end instead of 3.time do puts "Hi!" end I know this is not a good example, because for (({#times})) the block argument is optional. =end -- http://bugs.ruby-lang.org/