object IDuplicable.Duplicate(RubyContext /*!*/ context, bool copySingletonMembers) { var result = Copy(); context.CopyInstanceData(this, result, copySingletonMembers); return(result); }
public static bool TryDuplicateObject(RubyContext /*!*/ context, object obj, bool cloneSemantics, out object copy) { // Ruby value types can't be cloned if (RubyUtils.IsRubyValueType(obj)) { copy = null; return(false); } IDuplicable clonable = obj as IDuplicable; if (clonable != null) { copy = clonable.Duplicate(context, cloneSemantics); } else { // .NET classes and library clases that doesn't implement IDuplicable: copy = RubySites.Allocate(context.GetClassOf(obj)); context.CopyInstanceData(obj, copy, cloneSemantics); } // TODO: optimize _InitializeCopySharedSite.Target(_InitializeCopySharedSite, context, copy, obj); if (cloneSemantics) { context.FreezeObjectBy(copy, obj); } return(true); }
// Proc doesn't have "initialize_copy", it's entirely initialized in dup: object IDuplicable.Duplicate(RubyContext/*!*/ context, bool copySingletonMembers) { var result = Copy(); context.CopyInstanceData(this, result, copySingletonMembers); return result; }
/// <summary> /// Creates an empty copy of this instance, taint and instance variables. /// </summary> public MutableString /*!*/ Duplicate(RubyContext /*!*/ context, bool copySingletonMembers, MutableString /*!*/ result) { context.CopyInstanceData(this, result, false, false, copySingletonMembers); return(result); }
public static bool TryDuplicateObject(RubyContext/*!*/ context, object obj, bool cloneSemantics, out object copy) { // Ruby value types can't be cloned if (RubyUtils.IsRubyValueType(obj)) { copy = null; return false; } IDuplicable clonable = obj as IDuplicable; if (clonable != null) { copy = clonable.Duplicate(context, cloneSemantics); } else { // .NET classes and library clases that doesn't implement IDuplicable: copy = RubySites.Allocate(context.GetClassOf(obj)); context.CopyInstanceData(obj, copy, cloneSemantics); } // TODO: optimize _InitializeCopySharedSite.Target(_InitializeCopySharedSite, context, copy, obj); if (cloneSemantics) { context.FreezeObjectBy(copy, obj); } return true; }