Seriously: the session object is Ruby stdlib CGI::Session instance.
Which is a pseudo hash, to which you can add keys, and reassign their
values, but not permanently remove keys.
It would be nice to be able to do it, if only for debugging dumps of #session to be cleaner. But beyond that, I can’t see any real
ramifications for just clearing the values with “session[key] = nil”.
It won’t work; you’re calling method delete on the object stored in
session[‘myitem’]. In this case, you’d be calling ‘foo’.delete which
is String#delete and in any case has nothing to do with the
CGI::Session instance and/or its (pseudo) keys.
Are you sure about that? It shouldn’t be so, and some simple checks
with both debug(session) indicate it is not, exactly the same as for
the string key.
Moreover, note that even on a regular hash, setting key to value nil
would not eliminate the key. What the CGI::Session pseudo-hash
actually lacks is the Hash#delete method. Or rather, it has its own #delete, which does something else which you probably don’t want
(destroy the session). Bad design decision for a pseudo-hash object,
imho.
ramifications for just clearing the values with “session[key] = nil”.
By “bug” I mean the fact that the result of the two operations is not
consistent. As it turns out I was wrong and you just have to use
session.delete(key) just as with any Ruby hash, indifferent access or
not. Case closed
–
Julian ‘Julik’ Tarkhanov
please send all personal mail to
me at julik.nl