@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.
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.
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.
Ryan,
Can more than one attribute be combined / concatenated ?
e.g. :
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
@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.
http://m.onkey.org/2007/6/30/let-s-start-with-wtf
Apparently, nothing beats a good olf-fashioned block
Two ways to do :
1.find(:all).map{|t| t.name}
2.find(:all).collect(&:name)
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