RFC: `with ... yield` replacement

Another idea.

What if we use some special name for first block argument to mark it as implicit receiver?

Would it make quite obvious from first look what’s going on here? :thinking:

App.routes do |it, two, three|
  get :foo, two, third
end

Or maybe…

App.routes do |&., two, three|
  get :foo, two, three
end

Or…

App.routes do |&, two, three|
  get :foo, two, three
end

Also works with

App.routes { |&, two, three|  get :foo, two, three }

Calling multiple methods on implicit receiver is nice (the &. doesn’t allow this):
[1, 2, 3].map {|&| "#{to_s} : "{to_s(16)}" }

Expands to:
[1, 2, 3].map {|n| "#{n.to_s} : "{n.to_s(16)}" }

1 Like