RailsCasts Pro episodes are now free!
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
Hello! I could have sworn I’ve visited this site before but after browsing through many of the articles I realized it’s new to me. cerberus Anyhow, I’m certainly happy I came across it and I’ll be book-marking it and checking back often!
I wanted to thank you for this very good read!! I definitely enjoyed every bit of it. I have got you bookmarked to look at new stuff you post…
First sign in through GitHub to post a comment.