Class: Monolens::Type::Map
- Inherits:
-
Object
- Object
- Monolens::Type::Map
- Includes:
- ErrorHandling
- Defined in:
- lib/monolens/type/map.rb
Class Method Summary collapse
Instance Method Summary collapse
- #===(instance) ⇒ Object
- #dress(value, registry, &block) ⇒ Object
-
#initialize(key_type, value_type) ⇒ Map
constructor
A new instance of Map.
Methods included from ErrorHandling
Constructor Details
#initialize(key_type, value_type) ⇒ Map
Returns a new instance of Map.
6 7 8 9 |
# File 'lib/monolens/type/map.rb', line 6 def initialize(key_type, value_type) @key_type = key_type @value_type = value_type end |
Class Method Details
Instance Method Details
#===(instance) ⇒ Object
23 24 25 26 27 |
# File 'lib/monolens/type/map.rb', line 23 def ===(instance) instance.is_a?(::Hash) && instance.all?{|(k,v)| @key_type === k && @value_type === v } end |
#dress(value, registry, &block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/monolens/type/map.rb', line 15 def dress(value, registry, &block) fail!("Map expected, got #{value.class}", &block) unless value.is_a?(::Hash) value.each_with_object({}) do |(k,v), memo| memo[@key_type.dress(k, registry, &block)] = @value_type.dress(v, registry, &block) end end |