Class: Dry::Struct::Value

Inherits:
Dry::Struct show all
Defined in:
lib/dry/struct/value.rb

Overview

Value objects behave like Dry::Structs but deeply frozen using ice_nine

Examples:

class Location < Dry::Struct::Value
  attribute :lat, Types::Strict::Float
  attribute :lng, Types::Strict::Float
end

loc1 = Location.new(lat: 1.23, lng: 4.56)
loc2 = Location.new(lat: 1.23, lng: 4.56)

loc1.frozen? #=> true
loc2.frozen? #=> true
loc1 == loc2 #=> true

See Also:

Constant Summary

Constants inherited from Dry::Struct

Error, VERSION

Class Method Summary collapse

Methods inherited from Dry::Struct

#[], #constructor_type, #equalizer, #initialize, #input, #new, #schema, #to_hash

Methods included from ClassInterface

#argument_error_msg, #attribute, #attribute?, #attribute_names, #attributes, #call, #check_invalid_schema_keys, #constrained?, #constructor, #default?, #default_attributes, #failure, #inherited, #new, #optional?, #primitive, #result, #success, #try, #valid?

Constructor Details

This class inherits a constructor from Dry::Struct

Class Method Details

.newValue

Parameters:

Returns:

See Also:



26
27
28
# File 'lib/dry/struct/value.rb', line 26

def self.new(*)
  IceNine.deep_freeze(super)
end