It is worth noting that if you have an array of objects that you want to pass individually to a method with another caller, for example:
# erb <% strings = %w{ cat dog mouse rabbit } %> <% strings.each do |string| %> <%= t string %> <% end %>
To simplify, you can use the method method in combination with the behavior of the block extension:
<%= strings.map(&method(:t)).join(' ') %>
If you don't know what method does, it encapsulates the method associated with the character passed to it in Proc and returns it. Ampersand extends this Proc to a block that is pretty well passed to map . The return map is an array, and we probably want to format it a little nicer, hence join .
The caveat is that, as with Symbol#to_proc , you cannot pass arguments to the helper method.
coreyward Jul 27 '11 at 15:51 2011-07-27 15:51
source share