Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete multiple rails session variables in a single line

I have code that deleted multiple variables, as such...

session.delete(:a)
session.delete(:b)
session.delete(:c)
session.delete(:d)

is it possible to delete them all in one go instead of 4 lines?

like image 359
Gareth Burrows Avatar asked Mar 14 '23 21:03

Gareth Burrows


1 Answers

It is possible. Check out one way using basic Array#each method:

[:a, :b, :c, :d].each { |x| session.delete(x) }
like image 105
Andrey Deineko Avatar answered Mar 24 '23 22:03

Andrey Deineko