Mario Gr wrote:
> Is there a way to combine if and do into a single line?
>
> items.each do |item| if current_user.admin?
> #do stuff
> end
>
> Thanks!
Freddy Andersen wrote:
> items.each { |item| item.stuff? } if current_user.admin?
Which you actually COULD write like this too, but I'm not sure if it
would be considered easily readable:
items.each do |item|
#do stuff
end if current_user.admin?
The {| | } and the 'do' syntaxes are interchangeable in all ways. More
of a Ruby question than a Rails one.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---