class Hash
def to_proc
proc { |o| all? { |k, v| v === o[k] } }
end
end
This will allow to use hash as a proc argument for *Enumerable* methods.
Examples:
array = [{ key: "a" }, { key: "2aZ" }, { key: 12 }]
array.find(&{key: /Z/}) # => { key: "2aZ" }
array.select(&{key: 1..20}) # => [{ key: 12}]
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.