Class: Safer::HashProtocol::Only
- Defined in:
- lib/safer/hashprotocol.rb
Overview
Check that the Hash only contains elements that match the base Safer::HashProtocol object.
Instance Method Summary collapse
-
#===(h) ⇒ Object
Check that all keys in a hash are matched by the base HashProtocol object.
-
#initialize(base) ⇒ Only
constructor
The description for this object will be “ONLY #basebase.description”.
-
#match(h, remaining) ⇒ Object
Check that all keys in a hash are matched by the base HashProtocol object.
Methods inherited from Single
Methods inherited from Base
Constructor Details
#initialize(base) ⇒ Only
The description for this object will be “ONLY #Safer::HashProtocol::Only.basebase.description”.
276 277 278 |
# File 'lib/safer/hashprotocol.rb', line 276 def initialize(base) super("ONLY ", base) end |
Instance Method Details
#===(h) ⇒ Object
Check that all keys in a hash are matched by the base HashProtocol object.
282 283 284 285 286 287 288 289 |
# File 'lib/safer/hashprotocol.rb', line 282 def ===(h) remaining = h.dup if self.base.match(h, remaining) remaining.empty? else false end end |
#match(h, remaining) ⇒ Object
Check that all keys in a hash are matched by the base HashProtocol object. If they are, then empty remaining
.
293 294 295 296 297 298 299 300 |
# File 'lib/safer/hashprotocol.rb', line 293 def match(h, remaining) if self === h remaining.clear true else false end end |