Please read for an updated status on RailsCasts:
Learn more or hide this
Maybe a stupid question but is it possible to use Symbol to_proc even for methods which need an argument?
Nope, it only works on very simple method calls which don't take an argument. Anything more complicated and you will need to use the full block.
Can more than one attribute be combined / concatenated ?
Something like ... (this doesn't work) :
ActorNames = Actor.find(:all).collect(&:last_name + ' ' + &:first_name)
.. neither does :
ActorNames = Actor.find(:all).collect(&:last_name,&:first_name)
@Mike, nope, you can only call a single method with Symbol to_proc. If you want to combine two methods like you're trying to do, I recommend creating a new "full_name" method in the actor model to do this. That way you're back to calling one method.
Before your readers subscribe to this method, they should be aware of the performance issue.
Apparently, nothing beats a good olf-fashioned block
Two ways to do :
Symbol to_proc. If you want to combine two methods like you're trying to do, I recommend creating a new "full_name" method in the actor model to do this.
This episode has been updated to Rails 5 as a blog post. Shortcut Blocks with Symbol to_proc in Rails 5
Thanks for sharing. This is what I'm looking for. It's very easy to understand and I can't wait to try this out with this page
First sign in through GitHub to post a comment.