Class: Typespec::Hash
- Inherits:
-
Object
- Object
- Typespec::Hash
- Defined in:
- lib/typespec.rb
Overview
…
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(pairs = {}) ⇒ Hash
constructor
A new instance of Hash.
- #valid?(value) ⇒ Boolean
Constructor Details
#initialize(pairs = {}) ⇒ Hash
Returns a new instance of Hash.
101 102 103 104 |
# File 'lib/typespec.rb', line 101 def initialize(pairs={}) @pairs = pairs @pairs = {Typespec.anything => Typespec.anything} if @pairs.nil? or @pairs.empty? end |
Class Method Details
.[](pairs = {}) ⇒ Object
106 107 108 |
# File 'lib/typespec.rb', line 106 def self.[](pairs={}) Typespec::Hash.new(pairs) end |
Instance Method Details
#valid?(value) ⇒ Boolean
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/typespec.rb', line 110 def valid?(value) if value.is_a? ::Hash value.all? do |k, v| @pairs.any? do |pair| pair.zip([k,v]).all? {|typespec, value| typespec.valid?(value)} end end else false end end |