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
-
#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
#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
30 31 32 |
# File 'lib/types/types/typed_hash.rb', line 30 def name "T::Hash[#{keys.name}, #{values.name}]" end |
#new(*args, &blk) ⇒ Object
44 45 46 |
# File 'lib/types/types/typed_hash.rb', line 44 def new(*args, &blk) Hash.new(*T.unsafe(args), &blk) end |
#recursively_valid?(obj) ⇒ Boolean
overrides Base
35 36 37 |
# File 'lib/types/types/typed_hash.rb', line 35 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 |