internal static string /*!*/ FormatMethodMissingMessage(RubyContext /*!*/ context, object obj, string /*!*/ name, string /*!*/ message)
        {
            Assert.NotNull(name);

            string str;

            if (obj == null)
            {
                str = "nil:NilClass";
            }
            else if (_disableMethodMissingMessageFormatting)
            {
                str = RubyUtils.ObjectToMutableString(context, obj).ToString();
            }
            else
            {
                _disableMethodMissingMessageFormatting = true;
                try {
                    str = context.Inspect(obj).ConvertToString();
                    if (!str.StartsWith("#", StringComparison.Ordinal))
                    {
                        str += ":" + context.GetClassName(obj);
                    }
                } catch (Exception) {
                    // MRI: swallows all exceptions
                    str = RubyUtils.ObjectToMutableString(context, obj).ToString();
                } finally {
                    _disableMethodMissingMessageFormatting = false;
                }
            }

            return(FormatMessage(message, name, str));
        }
Example #2
0
 public static MutableString/*!*/ TagUri(RubyContext/*!*/ context, object self) {
     var result = MutableString.Create(Tags.RubyObject, context.GetIdentifierEncoding());
     var selfClass = context.GetClassOf(self);
     if (selfClass != context.ObjectClass) {
         return result.Append(':').Append(context.GetClassName(self));
     } else {
         return result;
     }
 }
Example #3
0
        public static object/*!*/ Xor(RubyContext/*!*/ context, object/*!*/ self, [NotNull]object/*!*/ other) {
            Debug.Assert(self is Enum);

            var result = EnumUtils.ExclusiveOr(self, other);
            if (result != null) {
                return result;
            }
            throw RubyExceptions.CreateUnexpectedTypeError(context, other, context.GetClassName(self));
        }
Example #4
0
 public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, RubyEncoding/*!*/ self) {
     // TODO: to_s overridden
     MutableString result = MutableString.CreateMutable();
     result.Append("#<");
     result.Append(context.GetClassName(self));
     result.Append(':');
     result.Append(self.Name);
     result.Append(">");
     return result;
 }
Example #5
0
        internal static MutableString /*!*/ GetTagUri(RubyContext /*!*/ context, object /*!*/ obj, string /*!*/ baseTag, Type /*!*/ baseType)
        {
            var result = MutableString.Create(baseTag, context.GetIdentifierEncoding());

            if (obj.GetType() != baseType)
            {
                return(result.Append(':').Append(context.GetClassName(obj)));
            }
            else
            {
                return(result);
            }
        }
        public static MutableString /*!*/ TagUri(RubyContext /*!*/ context, object /*!*/ self)
        {
            var    result    = MutableString.Create(Tags.TimestampYmd, context.GetIdentifierEncoding());
            string className = context.GetClassName(self);

            if (className != "Date")
            {
                return(result.Append(':').Append(className));
            }
            else
            {
                return(result);
            }
        }
        public static MutableString /*!*/ TagUri(RubyContext /*!*/ context, object self)
        {
            var result    = MutableString.Create(Tags.RubyObject, context.GetIdentifierEncoding());
            var selfClass = context.GetClassOf(self);

            if (selfClass != context.ObjectClass)
            {
                return(result.Append(':').Append(context.GetClassName(self)));
            }
            else
            {
                return(result);
            }
        }
Example #8
0
        public static MutableString/*!*/ Inspect(RubyContext/*!*/ context, Thread/*!*/ self) {
            RubyThreadInfo.RegisterThread(Thread.CurrentThread);

            MutableString result = MutableString.CreateMutable();
            result.Append("#<");
            result.Append(context.GetClassName(self));
            result.Append(':');
            RubyUtils.AppendFormatHexObjectId(result, RubyUtils.GetObjectId(context, self));
            result.Append(' ');

            RubyThreadStatus status = GetStatus(self);
            switch (status) {
                case RubyThreadStatus.Unstarted:
                    result.Append("unstarted");
                    break;
                case RubyThreadStatus.Running:
                    result.Append("run");
                    break;
                case RubyThreadStatus.Sleeping:
                    result.Append("sleep");
                    break;
                case RubyThreadStatus.Aborting:
                    result.Append("aborting");
                    break;
                case RubyThreadStatus.Completed:
                case RubyThreadStatus.Aborted:
                    result.Append("dead");
                    break;
            }

            result.Append('>');
            return result;
        }
 public static Exception /*!*/ CannotConvertTypeToTargetType(RubyContext /*!*/ context, object param, string /*!*/ toType)
 {
     Assert.NotNull(context, toType);
     return(CreateTypeConversionError(context.GetClassName(param), toType));
 }
Example #10
0
 public static Exception/*!*/ CreateUnexpectedTypeError(RubyContext/*!*/ context, object param, string/*!*/ type) {
     return CreateTypeError(String.Format("wrong argument type {0} (expected {1})", context.GetClassName(param), type));
 }
Example #11
0
        internal static string/*!*/ FormatMethodMissingMessage(RubyContext/*!*/ context, object obj, string/*!*/ name, string/*!*/ message) {
            Assert.NotNull(name);

            string str;
            if (obj == null) {
                str = "nil:NilClass";
            } else if (_disableMethodMissingMessageFormatting) {
                str = RubyUtils.ObjectToMutableString(context, obj).ToString();
            } else {
                _disableMethodMissingMessageFormatting = true;
                try {
                    str = context.Inspect(obj).ConvertToString();
                    if (!str.StartsWith("#", StringComparison.Ordinal)) {
                        str += ":" + context.GetClassName(obj);
                    }
                } catch (Exception) {
                    // MRI: swallows all exceptions
                    str = RubyUtils.ObjectToMutableString(context, obj).ToString();
                } finally {
                    _disableMethodMissingMessageFormatting = false;
                }
            }
            
            return FormatMessage(message, name, str);
        }
Example #12
0
 internal static MutableString/*!*/ GetTagUri(RubyContext/*!*/ context, object/*!*/ obj, string/*!*/ baseTag, Type/*!*/ baseType) {
     var result = MutableString.Create(baseTag, context.GetIdentifierEncoding());
     if (obj.GetType() != baseType) {
         return result.Append(':').Append(context.GetClassName(obj));
     } else {
         return result;
     }
 }
Example #13
0
 public static object SquareRoot(RubyContext/*!*/ context, BigDecimal/*!*/ self, object n) {
     throw RubyExceptions.CreateTypeError("wrong argument type " + context.GetClassName(n) + " (expected Fixnum)");
 }
Example #14
0
 public static Exception/*!*/ MethodShouldReturnType(RubyContext/*!*/ context, object param, string/*!*/ method, string/*!*/ targetType) {
     Assert.NotNull(context, method, targetType);
     return new InvalidOperationException(String.Format("{0}#{1} should return {2}",
         context.GetClassName(param), method, targetType
     ));
 }
Example #15
0
 public static MutableString TagUri(RubyContext/*!*/ context, object self) {
     return MutableString.CreateMutable(RubyEncoding.ClassName).
         Append("!ruby/exception:").
         Append(context.GetClassName(self));
 }
Example #16
0
 public static MutableString/*!*/ TagUri(RubyContext/*!*/ context, object self) {
     return MutableString.Create("!ruby/object:", RubyEncoding.ClassName).
         Append(context.GetClassName(self)).
         Append(' ');
 }
Example #17
0
 public static MutableString TagUri(RubyContext/*!*/ context, object/*!*/ self)
 {
     var result = MutableString.Create(Tags.TimestampYmd, context.GetIdentifierEncoding());
     string className = context.GetClassName(self);
     if (className != "Date") {
         return result.Append(':').Append(className);
     } else {
         return result;
     }
 }
        private object RequireWriteProtocol(RubyContext/*!*/ context, object value, string/*!*/ variableName) {
            if (!context.RespondTo(value, "write")) {
                throw RubyExceptions.CreateTypeError(String.Format("${0} must have write method, {1} given", variableName, context.GetClassName(value)));
            }

            return value;
        }
Example #19
0
 public static MutableString TagUri(RubyContext/*!*/ context, object self) {
     MutableString str = MutableString.Create("!ruby/object:");
     str.Append(context.GetClassName(self));
     str.Append(' ');
     return str;
 }
Example #20
0
 private static RubyIO/*!*/ ToIo(RubyContext/*!*/ context, object obj) {
     RubyIO io = obj as RubyIO;
     if (io == null) {
         throw RubyExceptions.CreateTypeConversionError(context.GetClassName(obj), "IO");
     }
     return io;
 }
Example #21
0
 public static Node ToYamlNode(RubyContext/*!*/ context, object self, RubyRepresenter rep) {
     throw RubyExceptions.CreateTypeError("can't dump anonymous class " + context.GetClassName(self));
 }
Example #22
0
 public static Exception/*!*/ CannotConvertTypeToTargetType(RubyContext/*!*/ context, object param, string/*!*/ toType) {
     Assert.NotNull(context, toType);
     return CreateTypeConversionError(context.GetClassName(param), toType);
 }
Example #23
0
        private static string/*!*/ FormatMethodMissingMessage(RubyContext/*!*/ context, object self, string/*!*/ name, string/*!*/ message) {
            Assert.NotNull(name);
            string strObject;

            if (self == null) {
                strObject = "nil:NilClass";
            } else {
                var site = context.StringConversionSite;
                strObject = (site.Target(site, self) as MutableString ?? RubyUtils.ObjectToMutableString(context, self)).ConvertToString();

                if (!strObject.StartsWith("#")) {
                    strObject += ":" + context.GetClassName(self);
                }
            }

            return String.Format(message, name, strObject);
        }