diff --git a/README.adoc b/README.adoc index 56558cc6..8865e346 100644 --- a/README.adoc +++ b/README.adoc @@ -3216,6 +3216,42 @@ def some_method(&) end ---- +=== Super Forwarding + +Use `super` without arguments when the enclosing methods arguments are the same. + +When super is called without arguments and parentheses Ruby will automatically forward the arguments taken by the method. + +[source,ruby] +---- +# bad +def some_method(*args, **kwargs) + super(*args, **kwargs) +end + +# good - implicitly passing all arguments +def method(*args, **kwargs) + super +end + +# good - forwarding a subset of the arguments +def method(*args, **kwargs) + super(*args) +end + +# good - calling super with different arguments +def method(*args, **kwargs) + super("foo", *args, **kwards) +end + +# good - forwarding no arguments +def method(*args, **kwargs) + super() +end +---- + +IMPORTANT: Blocks are always passed to the parent method. `&nil` can be passed to `super` if the block should remain local. + === Private Global Methods [[private-global-methods]] If you really need "global" methods, add them to Kernel and make them private.