rails/rails — pull request #11173 by davidbalbert (2013-06-29 02:29:45+00:00)
Title: Module#delegate cannot delegate to receivers named :args or :block for normal methods or :arg for setters.

I found this bug while trying to delegate to a method called `block`. Consider the following code:

```ruby
require 'active_support/core_ext'

class Foo
def block
@block ||= Object.new
end

delegate :dup, to: :block
end

Foo.new.dup
```

I expected this to return a new instance of `Object`, but instead it raised the following error:

```ruby
TypeError: can't dup NilClass
```

This is because `block` is an argument in the dynamically generated `dup` method on `Foo`. The signature of that method looks like this:

```ruby
class Foo
def dup(*args, &block)
# ...
end
end
```

No block is given to the `dup` call, so `block` is nil, thus the error. The same problem exists with delegating to `args` and delegating to `arg` if the method you're delegating happens to be an attribute writer.

I'm not super thrilled with how the tests turned out and would appreciate suggestions on how to make them a bit clearer and possibly shorter, but they fail without the patch and pass with it.

Please let me know if there's anything different I should have done.