I’m importing a value type from the CLR and I’d like to preserve value
semantics in Ruby … I’m not sure this can be done.
Consider the Point struct in C# as an example:
Point p1 = new Point(2, 3);
Point p2 = p1; // value types get copied in the CLR upon assignment
p2.X += 1;
Assert.Equals(p1.X + 1, p2.X);
So the equivalent code that uses my RubyCLR bridge doesn’t display the
p1 = Point.new(2, 3)
p2 = p1 # the object reference gets copied in Ruby, so this is now an
p2.X += 1
assert_equal p1.X, p2.X
The value types are stored as opaque blobs in Ruby’s T_DATA struct.
Since I can’t overload the assignment operator, are there any tricks
can help me? Or do I have to write a custom implementation of clone for
value types that memcpys the T_DATA struct?