tmp = reply.case.users.map(&:email)
tmp.delete(reply.created_by.email)
tmp.join(',')
@recipients = "#{tmp}"
Refactorings
No refactoring yet !
Martin Plöger
September 3, 2009, September 03, 2009 12:27, permalink
tmp = reply.case.users.map(&:email)
tmp.delete(reply.created_by.email)
tmp.join(',') #ATTENTION DEAD CODE!!! DON'T NEED THAT tmp is NOT changed by this and the result is not used by you. result = tmp.join(',')...
@recipients = "#{tmp}" # #{tmp} does a tmp.to_s. You could do @recipients = tmp.join(',') otherwise
#======>Refactoring 1:
mails = reply.case.users.map(&:email)
@recipients = mails.reject { |e| e == reply.created_by.email }.join(',')
#======>Refactoring 2:
#If reply.created_by is included in reply.case.users:
@recipients = reply.case.users.reject { |u| u == reply.created_by }.map(&:email).join(',')
#OR
@recipients = (reply.case.users - [reply.created_by]).map(&:email).join(',')
teamco-anthill.blogspot.com
September 3, 2009, September 03, 2009 13:51, permalink
Smaller version
@recipients = reply.case.users.map(&:email).delete(reply.created_by.email)*","
schnecki
September 3, 2009, September 03, 2009 19:41, permalink
@teamco Array#delete doesn't return the resulting array, it returns its argument, for whatever stupid reason
@recipients = (reply.case.users.map(&:email) - [reply.created_by.email]) * "," # or if reply.created_by is in reply.case.users: @recipients = (reply.case.users - [reply.created_by]).map(&:email) * ","
I wanted to remove specific e-mail address from array. How to do this better?
I need this in my mailer.