Method: Hash#delete

Defined in:
lib/source/ruby.rb

#delete(k) ⇒ Object

call-seq:

hsh.delete(key)                 -> value
hsh.delete(key) { |key| block } -> value

Deletes and returns a key-value pair from hsh whose key is equal to key. If the key is not found, returns the default value, or if the optional code block is given, pass in the requested key and return the result of block.

h = {:a => 100, :b => 200}

h.delete(:a)                                    #=> 100
h.delete(:z)                                    #=> nil
h.delete(:z) {|k| "#{k.inspect} not found" }    #=> ":z not found"


3271
3272
3273
3274
3275
# File 'lib/source/ruby.rb', line 3271

def delete(k)
  `var c=this.__contents__,d=this.__default__,x=k.m$hash(),kv=c[x]`
  `if(kv!=null){var result=kv[1];delete(c[x]);return result;}`
  return `typeof(_block)=='function'?#{yield `k`}:(typeof(d)=='function'?d(this,k):d)`
end