Class: Openai101::Types::HashType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Openai101::Types::HashType
- Defined in:
- lib/openai101/types/hash_type.rb
Overview
Used by the ActiveModel attributes API to cast values to hashes
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/openai101/types/hash_type.rb', line 7 def cast(value) case value when String JSON.parse(value) when Hash value else raise ArgumentError, "Cannot cast #{value.class} to Hash" end end |
#serialize(value) ⇒ Object
18 19 20 |
# File 'lib/openai101/types/hash_type.rb', line 18 def serialize(value) value.to_json end |