Forum: Ruby-core [ruby-trunk - Feature #9174][Open] value receiving block for Hash#has_key?

C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 rits (First Last) (Guest)
on 2013-11-28 22:33
(Received via mailing list)
Issue #9174 has been reported by rits (First Last).

----------------------------------------
Feature #9174: value receiving block for Hash#has_key?
https://bugs.ruby-lang.org/issues/9174

Author: rits (First Last)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Seems useful to be able to check for presence (as opposed to falsyness)
and receive the value

class Hash
  def has_key?(key, &block)
    val = fetch(key){return false}
    block.(val) if block
    true
  end
end


if h.has_key? :key do |val|
  #
end; else
  #
end
This topic is locked and can not be replied to.