Created
May 28, 2014 18:08
-
-
Save tkwidmer/44b49af34bce75165a87 to your computer and use it in GitHub Desktop.
is there a cleaner way to do an each but only if the array exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if array | |
array.each do | elm | | |
elm.doing_stuff | |
end | |
end |
array.each { |elm| elm.doing.stuff } if array
Another approach:
array.each do |elm|
elm.doing_stuff
end if array
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're in Rails, this should work: