Separate data transformation from side effects by replacing an imperative loop with a sequence of functional operations.
sessions.each do |token|
if session.token != current_session.token
session.token.expire!
end
end
sessions.map(&:token)
.reject { |t| t == current_session.token }
.each(&:expire!)