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 ”.



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

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.



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

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.



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

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