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`](github.com/dkubb/ice_nine)

Examples:

class Location < Dry::Struct::Value
  attribute :lat, Types::Float
  attribute :lng, Types::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

Instance Attribute Summary

Attributes inherited from Dry::Struct

#attributes

Class Method Summary collapse

Methods inherited from Dry::Struct

#[], #deconstruct_keys, #initialize, #inspect, loader, #new, #pretty_print, #schema, #to_h

Methods included from ClassInterface

#===, #abstract, #attribute, #attribute?, #attribute_names, #attributes, #attributes_from, #call_safe, #call_unsafe, #constrained?, #constructor, #default?, #failure, #has_attribute?, #inherited, #load, #meta, #new, #optional?, #primitive, #result, #success, #to_ast, #to_proc, #transform_keys, #transform_types, #try, #try_struct, #|

Constructor Details

This class inherits a constructor from Dry::Struct

Class Method Details

.newValue

Parameters:

Returns:

See Also:



32
33
34
# File 'lib/dry/struct/value.rb', line 32

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