public static CreateTypeError ( |
||
innerException | ||
message | string | |
Результат |
internal static RubyModule /*!*/ DefineModule(Scope /*!*/ autoloadScope, RubyModule /*!*/ owner, string /*!*/ name) { Assert.NotNull(autoloadScope, owner); object existing; if (owner.TryGetConstant(autoloadScope, name, out existing)) { RubyModule module = existing as RubyModule; if (module == null || module.IsClass) { throw RubyExceptions.CreateTypeError(String.Format("{0} is not a module", name)); } return(module); } else { // create class/module object: return(owner.Context.DefineModule(owner, name)); } }
/// <summary> /// Casts to symbol. Note that this doesn't actually use to_sym -- it uses to_str. /// That's just how Ruby does it. /// /// Another fun detail: you can pass Fixnums as Symbols. If you pass a Fixnum that /// doesn't map to a Symbol (i.e. Fixnum#to_sym returns nil), you get an ArgumentError /// instead of a TypeError. At least it produces a warning about using Fixnums as Symbols /// </summary> public static string /*!*/ CastToSymbol(RubyContext /*!*/ context, object obj) { if (obj is SymbolId) { return(SymbolTable.IdToString((SymbolId)obj)); } if (obj is int) { return(RubyOps.ConvertFixnumToSymbol(context, (int)obj)); } else { MutableString str = AsString(context, obj); if (str != null) { return(RubyOps.ConvertMutableStringToSymbol(str)); } } throw RubyExceptions.CreateTypeError(String.Format("{0} is not a symbol", RubySites.Inspect(context, obj))); }
private static RubyClass /*!*/ ToSuperClass(RubyContext /*!*/ ec, object superClassObject) { if (superClassObject != null) { RubyClass superClass = superClassObject as RubyClass; if (superClass == null) { throw RubyExceptions.CreateTypeError(String.Format("superclass must be a Class ({0} given)", ec.GetClassOf(superClassObject).Name)); } if (superClass.IsSingletonClass) { throw RubyExceptions.CreateTypeError("can't make subclass of virtual class"); } return(superClass); } else { return(ec.ObjectClass); } }
/// <summary> /// Like CastToInteger, but converts the result to an unsigned int. /// </summary> public static ulong CastToUInt64Unchecked(RubyContext /*!*/ context, object obj) { if (obj == null) { throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer"); } int fixnum; BigInteger bignum; CastToInteger(context, obj, out fixnum, out bignum); if ((object)bignum != null) { ulong u; if (bignum.AsUInt64(out u)) { return(u); } throw RubyExceptions.CreateRangeError("bignum too big to convert into `quad long'"); } return(unchecked ((ulong)fixnum)); }