Class: T::Types::TypedHash
- Inherits:
-
TypedEnumerable
- Object
- Base
- TypedEnumerable
- T::Types::TypedHash
- Defined in:
- lib/types/types/typed_hash.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Untyped
Instance Method Summary collapse
- #build_type ⇒ Object
-
#initialize(keys:, values:) ⇒ TypedHash
constructor
A new instance of TypedHash.
-
#keys ⇒ Object
Technically we don’t need this, but it is a nice api.
-
#name ⇒ Object
overrides Base.
- #new(*args, &blk) ⇒ Object
-
#recursively_valid?(obj) ⇒ Boolean
overrides Base.
- #type ⇒ Object
- #underlying_class ⇒ Object
-
#valid?(obj) ⇒ Boolean
overrides Base.
-
#values ⇒ Object
Technically we don’t need this, but it is a nice api.
Methods inherited from TypedEnumerable
Methods inherited from Base
#==, #describe_obj, #error_message_for_obj, #error_message_for_obj_recursive, #hash, method_added, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(keys:, values:) ⇒ TypedHash
Returns a new instance of TypedHash.
10 11 12 13 |
# File 'lib/types/types/typed_hash.rb', line 10 def initialize(keys:, values:) @inner_keys = keys @inner_values = values end |
Instance Method Details
#build_type ⇒ Object
29 30 31 32 33 |
# File 'lib/types/types/typed_hash.rb', line 29 def build_type keys values super end |
#keys ⇒ Object
Technically we don’t need this, but it is a nice api
16 17 18 |
# File 'lib/types/types/typed_hash.rb', line 16 def keys @keys ||= T::Utils.coerce(@inner_keys) end |
#name ⇒ Object
overrides Base
36 37 38 |
# File 'lib/types/types/typed_hash.rb', line 36 def name "T::Hash[#{keys.name}, #{values.name}]" end |
#new(*args, &blk) ⇒ Object
50 51 52 |
# File 'lib/types/types/typed_hash.rb', line 50 def new(*args, &blk) Hash.new(*T.unsafe(args), &blk) end |
#recursively_valid?(obj) ⇒ Boolean
overrides Base
41 42 43 |
# File 'lib/types/types/typed_hash.rb', line 41 def recursively_valid?(obj) obj.is_a?(Hash) && super end |
#type ⇒ Object
25 26 27 |
# File 'lib/types/types/typed_hash.rb', line 25 def type @type ||= T::Utils.coerce([keys, values]) end |
#underlying_class ⇒ Object
6 7 8 |
# File 'lib/types/types/typed_hash.rb', line 6 def Hash end |