Possible Duplicate:
Ruby block and unparenthesized arguments
What is the difference or value of these block coding styles in Ruby?
I always thought that the following are just two ways of saying the same thing:
[1,2,3].collect{|i| i * 2}
[1,2,3].collect do |i|
i * 2
end
But I'm getting some weird behaviour in one of my ERB templates where the two syntaxes seem to do two different things. This code works great:
<%=raw @menu.collect { |m|
content_tag("li") {
link_to(m.capitalize, url_for(:controller => m))
}
} %>
But when I re-write it as:
<%=raw @menu.collect do |m|
content_tag("li") do
link_to(m.capitalize, url_for(:controller => m))
end
end %>
... I just end up with a concatenated string of my @menu items. Am I missing something? Is there some tiny grain of syntactic sugar getting in the way here?