Class: TypeStruct::HashOf

Inherits:
Object show all
Includes:
Unionable
Defined in:
lib/type_struct/ext.rb,
lib/type_struct/hash_of.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Unionable

#|

Constructor Details

#initialize(key_type, value_type) ⇒ HashOf

Returns a new instance of HashOf.



8
9
10
11
# File 'lib/type_struct/hash_of.rb', line 8

def initialize(key_type, value_type)
  @key_type = key_type
  @value_type = value_type
end

Instance Attribute Details

#key_typeObject (readonly)

Returns the value of attribute key_type.



7
8
9
# File 'lib/type_struct/hash_of.rb', line 7

def key_type
  @key_type
end

#value_typeObject (readonly)

Returns the value of attribute value_type.



7
8
9
# File 'lib/type_struct/hash_of.rb', line 7

def value_type
  @value_type
end

Instance Method Details

#===(other) ⇒ Object



13
14
15
16
17
18
# File 'lib/type_struct/hash_of.rb', line 13

def ===(other)
  return false unless Hash === other
  other.all? do |k, v|
    @key_type === k && @value_type === v
  end
end

#to_sObject Also known as: inspect



19
20
21
# File 'lib/type_struct/ext.rb', line 19

def to_s
  "#{self.class.name.split('::').last}(#{@key_type}, #{@value_type})"
end