Dear John,

Welcome to ref-value world!
I am not sure what is your problem in real, but I might suggest
you to read the clone and dup methods of Object class at
http://www.ruby-doc.org/core

Don't you think how deep your need to copy an object is
case by case after all?  I leave here three samples below.
sorry, if I haven't got the point.

BTW you wrote p1.X, p1.Y and so on, but starting with a
capital letter means a constant in Ruby language.
If you were about to mean variables, they should start with a small
such that p1.x, p1.y...

cheers,
nori


John Lam wrote:

>I'm importing a value type from the CLR and I'd like to preserve value type
>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
>equivalent semantics:
>
>p1 = Point.new(2, 3)
>p2 = p1  # the object reference gets copied in Ruby, so this is now an alias
>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 that
>can help me? Or do I have to write a custom implementation of clone for
>value types that memcpys the T_DATA struct?
>
>Thanks
>-John
>http://www.iunknown.com
>
>  
>