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
Behavior change when decorating array #362
Comments
|
Yeah, we have |
|
Yep, I changed the behaviour in 7748ce5, if you use As you can see from the diff there, having Apart from that implementation issue, I think it is more intention-revealing to have @steveklabnik This change probably needs to be documented. I can have a stab at updating the changelog and README if you want? |
|
Oh, cool. I missed decorate_collection. Excellent - should be solved with the documentation update then. I completely agree that not bundling the behavior into #decorate is the less surprising route. |
|
Ya a changeling needs built in general. I did it sorta with my blog post, |
|
@steveklabnik well, I'm still not sure about this decision. It was pretty handy to decorate collections with the same |
|
Well, the real problem is that we can't satisfy both cases automatically: If you want to create a decorator that wraps a collection, or you want a collection of decorated objects. I am not sure of the best way to resolve this. I agree that the method name is too long, but I'm not sure what to do about it. |
|
The magic required to detect collections is far too fallible. This alone is enough reason for me to prefer a distinct collection method. |
|
I agree that we need a separate method or means of invocation.
|
|
|
I like the above or |
|
In defence of my bike shed :)
It is a relatively long method name, for sure. But it's explicit and intention-revealing and not that long. |
|
There's an easy fix to make everyone happy. Just jam this in an initializer: BAM :D |
|
Ha! |
In 0.18, calling something like
FooDecorator.decorate([@foo])would return an array of decoratedFoos. It now tries to decorate the array itself. Is this desired behavior?I think this arose from aliasing
decoratetonew. Before, it had special behavior when passed an array.We have collection decorator, so we could make
decorateuse that if passed an array, or we could add something like aDecorator::decorate_allmethod which expects an Enumerable.I've worked around this in my code by using [@foo].map(&:decorate), which works fine, but the semantics are different since that doesn't ensure that I'm getting an array of FooDecorator back.
The text was updated successfully, but these errors were encountered: