Class: Safer::HashProtocol::All
- Defined in:
- lib/safer/hashprotocol.rb
Overview
Check that all of a set of Safer::HashProtocol objects match a Hash.
Instance Method Summary collapse
-
#===(h) ⇒ Object
Check if all elements from the
listargument to initialize match Hash h. -
#initialize(*list) ⇒ All
constructor
The description for this object will be the descriptions for each argument, separated by “ AND ”.
-
#match(h, remaining) ⇒ Object
Check if all elements from the
listargument to initialize match Hash h.
Methods inherited from Compound
Methods inherited from Base
Constructor Details
#initialize(*list) ⇒ All
The description for this object will be the descriptions for each argument, separated by “ AND ”.
220 221 222 |
# File 'lib/safer/hashprotocol.rb', line 220 def initialize(*list) super(" AND ", *list) end |
Instance Method Details
#===(h) ⇒ Object
Check if all elements from the list argument to initialize match Hash h.
227 228 229 |
# File 'lib/safer/hashprotocol.rb', line 227 def ===(h) self.list.all? do |el| el === h end end |
#match(h, remaining) ⇒ Object
Check if all elements from the list argument to initialize match Hash h. If they do, remaining will be updated to remove all matching elements from list. If not all elements match, remaining will be unmodified.
236 237 238 239 240 241 242 243 |
# File 'lib/safer/hashprotocol.rb', line 236 def match(h, remaining) nremaining = remaining.dup rval = self.list.all? do |el| el.match(h, nremaining) end if rval remaining.update(nremaining) end rval end |