Skip to content

Commit bd91345

Browse files
committed
Reintroduce IceNine for non-CRuby
1 parent f29959e commit bd91345

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

dry-struct.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
3131

3232
spec.required_ruby_version = ">= 3.1.0"
3333

34+
spec.add_runtime_dependency "ice_nine" if RUBY_ENGINE != "ruby"
3435
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
3536
spec.add_runtime_dependency "dry-core", "~> 1.1"
3637
spec.add_runtime_dependency "dry-types", "~> 1.8", ">= 1.8.2"

lib/dry/struct/value.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "ice_nine" if RUBY_ENGINE != "ruby"
4+
35
module Dry
46
class Struct
57
extend Core::Deprecations[:"dry-struct"]
@@ -24,7 +26,16 @@ class Value < self
2426

2527
# @param (see ClassInterface#new)
2628
# @return [Value]
27-
def self.new(*) = ::Ractor.make_shareable(super)
29+
def self.new(*)
30+
obj = super
31+
if defined?(::Ractor)
32+
::Ractor.make_shareable(obj)
33+
elsif defined?(::IceNine)
34+
::IceNine.deep_freeze(obj)
35+
else
36+
obj.freeze
37+
end
38+
end
2839
end
2940

3041
deprecate_constant :Value

0 commit comments

Comments
 (0)