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
        internal static RubyModule /*!*/ GetModuleFromObject(RubyContext /*!*/ context, object obj)
        {
            Assert.NotNull(context);
            RubyModule module = obj as RubyModule;

            if (module == null)
            {
                throw RubyExceptions.CreateTypeError(
                          RubyUtils.ObjectToMutableString(context, obj).Append(" is not a class/module").ConvertToString()
                          );
            }
            return(module);
        }