Class: Safer::HashProtocol::Any

Inherits:
Compound show all
Defined in:
lib/safer/hashprotocol.rb

Overview

Check that at least one of a set of Safer::HashProtocol objects matches a Hash.

Instance Method Summary collapse

Methods inherited from Compound

#self

Methods inherited from Base

#self

Constructor Details

#initialize(*list) ⇒ Any

The description for this object will be the descriptions for each argument, separated by “ OR ”.



190
191
192
# File 'lib/safer/hashprotocol.rb', line 190

def initialize(*list)
  super(" OR ", *list)
end

Instance Method Details

#===(h) ⇒ Object

Check if any elements from the list argument to initialize match Hash h.



197
198
199
# File 'lib/safer/hashprotocol.rb', line 197

def ===(h)
  self.list.any? do |el| el === h end
end

#match(h, remaining) ⇒ Object

Check if any elements from the list argument to initialize match Hash h, keeping track of which elements from h have not been matched.



204
205
206
207
208
209
210
211
212
# File 'lib/safer/hashprotocol.rb', line 204

def match(h, remaining)
  self.list.inject(false) do |memo, el|
    if el.match(h, remaining)
      true
    else
      memo
    end
  end
end