Project

General

Profile

Feature #9174

value receiving block for Hash#has_key?

Added by rits (First Last) almost 6 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:58668]

Description

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

Also available in: Atom PDF