How to unset a hash member?

how do i unset a hash member (as in php)?

h[‘a’] = ‘aaa’
h[‘b’] = ‘bbb’
h[‘c’] = ‘ccc’

h >> { ‘a’ => ‘aaa’, ‘b’ => ‘bbb’, ‘c’ => ‘ccc’ }

something like this:
h[‘b’].delete
h >> { ‘a’ => ‘aaa’, ‘c’ => ‘ccc’ }

not like this:
h[‘b’] = nil
h >> { ‘a’ => ‘aaa’, ‘b’ => nil, ‘c’ => ‘ccc’ }

thanks. :slight_smile:

something like this:
h[‘b’].delete
h >> { ‘a’ => ‘aaa’, ‘c’ => ‘ccc’ }

C:\Documents and Settings\flifson>irb
irb(main):001:0> h={‘a’=>‘aaa’,‘b’=>‘bbb’}
=> {“a”=>“aaa”, “b”=>“bbb”}
irb(main):002:0> h.delete(‘b’)
=> “bbb”
irb(main):003:0> h
=> {“a”=>“aaa”}
irb(main):004:0>

On 7/3/06, aa bb [email protected] wrote:

how do i unset a hash member (as in php)?

Hash.delete(key)…

hsh = { ‘a’ => “test”, “b” => “testagain” }
hsh.delete(‘a’)
hsh is now {“b”=>“testagain”}

h[‘a’] = ‘aaa’

:o that easy? thanks. :slight_smile: i feel silly now.

how to do this with ruby on rails session? because it didn’t work.

session[‘a’] = 123
session.delete(‘a’) <<< error

i can do this though:
session.model.data.delete(‘a’) <<< it worked

there must be a better way?

On Jul 3, 2006, at 12:51 AM, aa bb wrote:

there must be a better way?
You’ll have to ask on the Rails mailing list.

http://lists.rubyonrails.org


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs