New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Module#delegate_missing_to in the guides #29268

Merged
merged 1 commit into from Jun 11, 2017

Conversation

Projects
None yet
5 participants
@gsamokovarov
Contributor

gsamokovarov commented May 29, 2017

Added a small section for it in the Active Support Core Extensions
guide.

@rails-bot

This comment has been minimized.

rails-bot commented May 29, 2017

r? @matthewd

(@rails-bot has picked a reviewer for you, use r? to override)

@gsamokovarov

This comment has been minimized.

Contributor

gsamokovarov commented May 29, 2017

screen shot 2017-05-29 at 16 00 08

guides/source/active_support_core_extensions.md Outdated
variables, methods, constants, etc.
WARNING: The delegated method calls must be public on the target, otherwise
they will raise `NoMethodError`.

This comment has been minimized.

@matthewd

matthewd May 29, 2017

Member

This warning demonstrates that the behaviour doesn't match your manual implementation. 😉

Really though, I think the full method_missing/respond_to_missing? illustration is too much unnecessary detail. It works for delegate, but isn't an efficient use of space in general. Let's ditch it, and just focus on usage.

Maybe also consider reusing the User/Profile example... "or you could just forward everything" seems a logical leap from "here's how to delegate 4 methods in one line"

This comment has been minimized.

@gsamokovarov

gsamokovarov May 29, 2017

Contributor

Sure, I will try that! I :)

@gsamokovarov

This comment has been minimized.

Contributor

gsamokovarov commented May 30, 2017

screen shot 2017-05-30 at 11 03 49

@matthewd I have condensed the example to the one above. Are you okay with it?

@gsamokovarov gsamokovarov force-pushed the gsamokovarov:delegate-missing-to-guides branch May 30, 2017

guides/source/active_support_core_extensions.md Outdated
#### `delegate_missing_to`
Imagine you would like to delegate all of the `Profile` methods to the `User`
object. Instead of listing every `Profile` method in a `delegate` call, you can

This comment has been minimized.

@matthewd

matthewd May 30, 2017

Member

delegate all of the Profile methods to the User object

That sounds around the wrong way -- though the exact opposite isn't right either.

'to' -> 'from' might be sufficient?

This comment has been minimized.

@gsamokovarov

gsamokovarov May 30, 2017

Contributor

Updated it to:

Imagine you would like to delegate all methods from the Profile to the User
object...

Does it feel better now?

This comment has been minimized.

@matthewd

matthewd May 30, 2017

Member

No, because that still doesn't match what the code says: User.delegate_missing_to :profile

This comment has been minimized.

@gsamokovarov

gsamokovarov May 30, 2017

Contributor

So another take, this time trying to go with what the code says. 😅

Imagine you would like to delegate everything missing from the User object,
to the Profile one. The delegate_missing_to macro let's you implement this
in a breeze:

This comment has been minimized.

@matthewd

matthewd May 30, 2017

Member

☝🏻 looks good

("lets" not "let's")

This comment has been minimized.

@gsamokovarov

@gsamokovarov gsamokovarov force-pushed the gsamokovarov:delegate-missing-to-guides branch 4 times, most recently May 30, 2017

guides/source/active_support_core_extensions.md Outdated
The target can be anything callable within the object, e.g. instance variables,
methods, constants, etc.
NOTE: Defined in `active_support/core_ext/module/delegation.rb`

This comment has been minimized.

@vipulnsward

vipulnsward Jun 11, 2017

Member

lgtm. We should mention only public methods are delegated.

This comment has been minimized.

@gsamokovarov

gsamokovarov Jun 11, 2017

Contributor

Just dropped it in a sentence. If you think a warning, like the one in #29268 (comment) works better, ping me and I'll change it.

Document Module#delegate_missing_to in the guides
Added a small section for it in the `Active Support Core Extensions`
guide. [ci skip]

@gsamokovarov gsamokovarov force-pushed the gsamokovarov:delegate-missing-to-guides branch to 43512df Jun 11, 2017

@vipulnsward vipulnsward merged commit 1d2cc13 into rails:master Jun 11, 2017

1 check passed

codeclimate no new or fixed issues
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment