Sha256: ff44f4b33ab47bde57d6db93de22f3dd619ca5299573f441807200708b3ea840

Contents?: true

Size: 813 Bytes

Versions: 8

Compression:

Stored size: 813 Bytes

Contents

require 'ice_nine'

module Dry
  class Struct
    # {Value} objects behave like {Struct}s but *deeply frozen*
    # using [`ice_nine`](https://github.com/dkubb/ice_nine)
    #
    # @example
    #   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 https://github.com/dkubb/ice_nine
    class Value < self
      # @param (see ClassInterface#new)
      # @return [Value]
      # @see https://github.com/dkubb/ice_nine
      def self.new(*)
        IceNine.deep_freeze(super)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dry-struct-1.0.0 lib/dry/struct/value.rb
dry-struct-0.7.0 lib/dry/struct/value.rb
dry-struct-0.6.0 lib/dry/struct/value.rb
dry-struct-0.5.1 lib/dry/struct/value.rb
dry-struct-0.5.0 lib/dry/struct/value.rb
dry-struct-0.4.0 lib/dry/struct/value.rb
dry-struct-0.3.1 lib/dry/struct/value.rb
dry-struct-0.3.0 lib/dry/struct/value.rb