diff --git a/dry-struct.gemspec b/dry-struct.gemspec index 121624b..af8ed24 100644 --- a/dry-struct.gemspec +++ b/dry-struct.gemspec @@ -31,10 +31,10 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 3.1.0" + spec.add_runtime_dependency "ice_nine" if RUBY_ENGINE != "ruby" spec.add_runtime_dependency "zeitwerk", "~> 2.6" spec.add_runtime_dependency "dry-core", "~> 1.1" spec.add_runtime_dependency "dry-types", "~> 1.8", ">= 1.8.2" - spec.add_runtime_dependency "ice_nine", "~> 0.11" spec.add_development_dependency "bundler" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" diff --git a/lib/dry/struct/value.rb b/lib/dry/struct/value.rb index 82e4544..2090ac0 100644 --- a/lib/dry/struct/value.rb +++ b/lib/dry/struct/value.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require "ice_nine" +require "ice_nine" if RUBY_ENGINE != "ruby" module Dry class Struct extend Core::Deprecations[:"dry-struct"] # {Value} objects behave like {Struct}s but *deeply frozen* - # using [`ice_nine`](https://github.com/dkubb/ice_nine) + # using `Ractor.make_shareable` on CRuby, or `IceNine` on other engines # # @example # class Location < Dry::Struct::Value @@ -21,15 +21,21 @@ class Struct # loc1.frozen? #=> true # loc2.frozen? #=> true # loc1 == loc2 #=> true - # - # @see https://github.com/dkubb/ice_nine class Value < self abstract # @param (see ClassInterface#new) # @return [Value] - # @see https://github.com/dkubb/ice_nine - def self.new(*) = ::IceNine.deep_freeze(super) + def self.new(*) + obj = super + if defined?(::Ractor) + ::Ractor.make_shareable(obj) + elsif defined?(::IceNine) + ::IceNine.deep_freeze(obj) + else + obj.freeze + end + end end deprecate_constant :Value diff --git a/repo-sync.yml b/repo-sync.yml index 4b04f45..50c37e7 100644 --- a/repo-sync.yml +++ b/repo-sync.yml @@ -17,4 +17,3 @@ gemspec: - [zeitwerk, "~> 2.6"] - [dry-core, "~> 1.1"] - [dry-types, "~> 1.8", ">= 1.8.2"] - - [ice_nine, "~> 0.11"]